0

我目前正在使用自定义 UITableViewCell 构建一个 tableview。我以前做过很多次,但由于某种原因,细胞没有正确显示。另外,当我向上滚动时,文本标签开始消失,此时我不知道为什么。这是 cellForRowAtIndexPath 方法:

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"Row: %i Section: %i", indexPath.row , indexPath.section);
HollerCommentCell *cell = (HollerCommentCell *)[table dequeueReusableCellWithIdentifier:@"HollerCommentCell"];
if( !cell )
{
    //Initialize a new cell
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HollerCommentCell" owner:nil options:nil];
    for( id currentObject in topLevelObjects )
    {
        if([currentObject isKindOfClass:[HollerCommentCell class]]){
            cell = (HollerCommentCell*)currentObject;
            break;
        }
    }
}
[[cell name]setText:@"Nick"];
[[cell commentText]setText:@"Hello"];
return cell;
}

这也是我的 numberOfRowsInSection 方法的副本:

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
    return ( section == 0 ) ? 5 : 0;
}

这是它如何工作的屏幕截图:

在此处输入图像描述

不知道现在发生了什么。想法?

4

1 回答 1

0

看起来您关闭了剪辑,并且 commentText 标签的位置太低了 44 点。效果是 commentText 出现在它应该设置的单元格正下方的行中。

也许你应该在你的单元格中查看 NSLog 视图并查看它们的框架的位置。

于 2012-07-25T00:33:19.027 回答