UITableView第一页单元格未显示

时间:2013-09-07 00:37:48

标签: ios objective-c uitableview

我继承了一个旧的iPhone应用程序,我正在从NIB转换为故事板。我似乎无法弄清楚的一件事是UITableView中的第一页单元格被背景颜色覆盖。我已经验证了正在创建和填充单元格。但我只是看不到他们。一旦我向下滚动,下面的单元格看起来很好。

TableView代码:

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return segment_SECTION_HEIGHT;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return segment_CELL_HEIGHT;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSArray * allKeys = [segmentsByTimeDictionary allKeys];
    return allKeys.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *date = [timeSections objectAtIndex: section];
    NSMutableArray *timesegments = [segmentsByTimeDictionary objectForKey: date];

    return timesegments.count;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSString *date = [timeSections objectAtIndex: section];
    UIView *headerView = [[GradientView alloc] initWithStartColor: segment_SECTION_COLOR_TOP endColor: segment_SECTION_COLOR_BOTTOM];
    headerView.frame = CGRectMake(0, 0, tableView.frame.size.width, segment_SECTION_HEIGHT);
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:
                          CGRectMake(10, 0, 320, segment_SECTION_HEIGHT)];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.font = [UIFont boldSystemFontOfSize: 16];
    timeLabel.text = date;
    timeLabel.textColor = segment_SECTION_TEXT_COLOR;

    [headerView addSubview: timeLabel];

    return headerView;
//    return date;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"segmentCell";
    segmentCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
    NSDate *date = [timeSections objectAtIndex: indexPath.section];
    NSMutableArray *timesegments = [segmentsByTimeDictionary objectForKey: date];
    segments *segment = [timesegments objectAtIndex: indexPath.row];
    [cell setName: segment.name];

    return cell;
}

编辑添加:我注意到如果我从viewDidLoad中删除了这个函数调用,那么它就会消失:

drawGradientBackground(self.view, DEFAULT_BACKGROUND_TOP, DEFAULT_BACKGROUND_BOTTOM);

该功能定义为

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.colors = [NSArray arrayWithObjects: (id) startColor.CGColor, (id) endColor.CGColor, nil];
gradient.frame = view.layer.bounds;

[view.layer insertSublayer: gradient atIndex: 0];

截图: UITableView Screenshot

0 个答案:

没有答案