简体   繁体   English

自定义UITableViewCell标签消失

[英]Custom UITableViewCell labels disappearing

I'm currently building a tableview with custom UITableViewCell. 我目前正在使用自定义UITableViewCell构建一个tableview。 I've done this a ton of times before but for some reason the cells aren't showing up right. 我已经做过很多次了,但是由于某种原因,这些单元无法正确显示。 Also as I scroll up the text labels start disappearing and at this point I have no idea why. 另外,当我向上滚动时,文本标签开始消失,这时我不知道为什么。 Here's the cellForRowAtIndexPath method: 这是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;
}

Also here's a copy of my numberOfRowsInSection method: 这也是我的numberOfRowsInSection方法的副本:

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

Here's a screenshot of how it works: 以下是其工作原理的屏幕截图:

在此处输入图片说明

No idea what's going on now. 不知道现在发生了什么。 Thoughts? 有什么想法吗?

It looks like you have clipping turned off and the commentText label is sitting 44 points too low. 好像您已关闭剪辑,并且commentText标签的位置太低了44点。 The effect is the commentText is appearing the the row directly below the cell it should be setting in. 结果是commentText出现在应设置单元格正下方的行中。

Maybe you should NSLog views in your cell and see where their frames are positioned at. 也许您应该在单元格中使用NSLog视图,并查看其框架的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM