自定义的UITableViewCell不会显示标签文本(custom uitableviewcell

2019-08-17 06:25发布

而唱片公司的价值是零为好。

我真的不知道发生了什么事情。

这些都是我的课/码

@interface CustomEventCell : UITableViewCell{

}

@property (nonatomic, weak) IBOutlet UILabel *participant1label;
@property (nonatomic, weak) IBOutlet UILabel *participant2label;
@property (nonatomic, weak) IBOutlet UILabel *status;

@end

事件模型

@interface Event : NSObject{
}
@property NSNumber *matchId;
@property NSString *participant1, *participant2,
-(id)init;
@end

这是填补了电池的实现代码如下

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"EventCell";

    CustomEventCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil)
    {
        cell = [[CustomEventCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // events is a NSMutableArray with Event instances
    Event *event = [events objectAtIndex:indexPath.row];

    cell.participant1label.text = event.participant1;

    return cell;
   }

这里是我的设置

我必须失去了一些东西,因为我有其他的UITableView,它populatees定制没有问题。 我比较了他们,他们是一致的。 我甚至试图要回常规标签,这将填补起来,但没有这个习俗之一。

编辑:

修改错误复制的代码。

Answer 1:

我写了一个简单的小测试程序试图复制你希望看到什么样的工作。 我已可以在这里用故事板。 如果你不能从这个数字出来,那么也许你可以把测试应用程序并修改它,以便它复制您所看到的不良行为。

我最好的猜测,可能什么的,就是当你初始化你的细胞,它没有连接到在厦门国际银行视图。

尝试设置断点:

cell.participant1label.text = event.participant1;

并验证cell.participant1label不是做零:

NSLog( @"cell.participant1label: %@", cell.participant1label );

我在其中没有我的自定义标签都显示了一个小错误,cell.participant1label为零。 其原因是,我没有设置自定义表视图细胞“EventCell”的标识。 所以,我可能会建议该复核,并确保该标识符确实你的代码和厦门国际银行之间的匹配。



文章来源: custom uitableviewcell will not display label texts