【发布时间】:2013-08-29 17:30:39
【问题描述】:
我知道这个问题在这里一次又一次地被问到,但没有找到任何解决我的问题的方法。我正在通过 xib 创建一个自定义 UITableViewCell 并尝试加载它。在我的 VC 中调用 ACSumaryVC
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"SimpleTableCell";
AcSummaryCell *cell = (AcSummaryCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AcSummaryCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
}
AcSummaryCell 是 UITableViewCell 的子类,它有一个名为 acLabel 的 UILabel IBOutlate。当我编译项目时出现以下错误 -
`Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ACSummaryVC 0x71465c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key acLabel.'`
我已经在 AcSummayCell 类中创建了 acLabel 连接,但我从 ACSummaryVC 收到错误消息?我做错了什么?
编辑:- 根据下面 Mani 的回答,我正在延迟连接到文件所有者,这是错误的,而是我必须延迟连接到自定义单元格。但是当我尝试这个时,我没有得到我迟到了,而不是我越来越喜欢这张图片-
现在的问题是如何将我的 outlate 与自定义单元格连接起来? 这是我的 AcSummayCell.h
@interface AcSummayCell : UITableViewCell
@property(nonatomic, retain)IBOutlet UILabel* acLabel;
@property(nonatomic, retain)IBOutlet UILabel* namelbl;
@property(nonatomic, retain)IBOutlet UILabel* cBalancelbl;
@property(nonatomic, retain)IBOutlet UILabel* avBalancelbl;
和 AcSummayCell.m
#import "AcSummayCell.h"
@implementation AcSummayCell
@synthesize acLabel = _acLabel;
@synthesize namelbl = _namelbl;
@synthesize cBalancelbl = _cBalancelbl;
@synthesize avBalancelbl = _avBalancelbl;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
【问题讨论】:
-
您是否将xib中的自定义类设置为ACSummayCell?
-
是的,我做到了。并尝试删除并重新创建连接/xib 等。但没有运气。
-
检查一切是否连接良好,或者您的 xib 文件中没有错误的引用。
-
检查acLabel是否正确连接?
-
我这样做了,甚至重新创建了我的 UITabelViewCell 子类和 xib.. 对我来说奇怪的是,我正在 AcSummaryCell 中创建连接并为 ACSummaryVC 获取错误。
标签: ios objective-c uitableview