我目前正在使用自定义 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;
}
这是它如何工作的屏幕截图:
不知道现在发生了什么。想法?