本文介绍了自定义uitableviewcell将不显示标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标签的值也为null。

And the value of the labels are null as well.

我不知道发生了什么。

这是我的课程/

These are my classes/codes

@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,它填充了自定义没有问题。我比较他们,他们是相同的。我甚至试图回到正规的标签,它会填补,但不是这个定制的。

I must be missing something as I have another uitableview and it populatees the custom without problems. I compared them and they're identical. I even tried going back to the regular label and it would fill that up but not this custom one.

编辑:

修改错误的复制代码。

推荐答案

我写了一个简单的小测试应用程序试图复制你想看到的工作。我已使用Storyboards 。如果你不能从中找出来,那么也许你可以采取测试应用程序,并修改它,以便它复制你所看到的不良行为。

I wrote a simple little test app attempting to replicate what you want to see working. I have made it available here using Storyboards. If you cannot figure it out from this, then perhaps you can take the test app and modify it so that it replicates the bad behavior you are seeing.

我最好的猜测

尝试在以下位置设置断点:

Try setting a breakpoint at:

cell.participant1label.text = event.participant1;

并通过执行以下操作验证cell.participant1label是否为nil:

and verify that cell.participant1label is not nil by doing:

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

我有一个小错误,其中没有我的自定义标签显示,cell.participant1label是nil 。原因是我没有将自定义表视图单元格的标识符设置为EventCell。所以,我可能建议重新检查,并确保标识符真正匹配您的代码和XIB之间。

I had a small bug in which none of my custom labels were showing up and cell.participant1label was nil. The cause was that I had not set the Identifier for the custom table view cell to 'EventCell'. So, I might suggest rechecking that and making sure the identifier really does match between your code and the XIB.

这篇关于自定义uitableviewcell将不显示标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 16:16