1

我继承了一个旧的 iPhone 应用程序,我正在将它从 NIB 转换为情节提要。我似乎无法弄清楚的一件事是 UITableView 中单元格的第一页被背景颜色覆盖。我已验证正在创建并填写单元格。但我就是看不到他们。向下滚动后,下部单元格看起来很好。

表视图代码:

- (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 截图

4

0 回答 0