具有自定义单元格的表格视图

got*_*tye 6 customization row cell reusability uitableview

到目前为止,我曾经创建自定义笔尖来制作我想要的单元格,但这一次,单元格的高度将从一个变为另一个,这样我就无法创建一个固定大小的单元格的笔尖.

所以我决定以编程方式创建它...是否正确的方式实现它?

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        UILabel *pseudoAndDate = [[UILabel alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,20.0)];
        [pseudoAndDate setTag:1];
        [cell addSubview:pseudoAndDate];
        [pseudoAndDate release];
    }

    CommentRecord *thisRecord = [comments objectAtIndex:[indexPath row]];

    UILabel *label = (UILabel *)[cell viewWithTag:1];
    [label setText:[NSString stringWithFormat:@"%@ | %@",thisRecord.author,thisRecord.date]];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

或者..我在这里错过了什么?到目前为止它似乎不起作用;)

谢谢,

高堤耶.

got*_*tye 0

以编程方式自定义 UITableViewCell 的新链接Apple 文档 UITableViewCell