2012-07-24 67 views
0

我目前正在用自定义UITableViewCell构建tableview。我之前做过这么多次,但由于某些原因,这些细胞并没有显示正确。当我滚动文本标签开始消失,在这一点上,我不知道为什么。这里的的cellForRowAtIndexPath方法:自定义UITableViewCell标签消失

- (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; 
} 

这里是它是如何工作的截图:

enter image description here

不知道这是怎么回事现在。思考?

+0

所以为了让这一切顺利 - 当你第一次看到这个视角时,一切看起来都很完美。但是你不能真的向右滚动,你只有5个单元格?细胞数量是否改变?如果它确实重新加载表格后? – 2012-07-25 00:48:25

回答

0

它看起来像你有剪辑关闭和commentText标签坐44太低。效果是commentText出现在应该设置的单元正下方的行中。

也许你应该在你的单元格中查看NSLog视图,看看它们的框架位于何处。

+0

是的,我在想同样的事情 - 但我得到的印象是,第一次都完全展现出来 - 让我们看看答案:-) – 2012-07-25 00:49:19

+0

是的,你说得对:)我完全没有调整评论文本栏的大小基于评论长度。看起来我不擅长复制我自己的代码! – 2012-07-25 02:03:34