我已经查看了StackOverflow上所有与此相关的问题,并尝试了它们所有可能的解决方案,但我仍然无法弄清楚为什么会出现这个错误:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CustomCell 0x6e627d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key title.'
我正在尝试使用nibName:“CustomCell”加载自定义的表视图单元格。它的类被分配为“CustomCell”(与nib名称相同的类名)。它的文件所有者也设置为加载此单元格的类 - “ProductsTableViewControllerWithSearch”。nib中的所有插座都连接到CustomCell.m中的插座。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellClassName = @"CustomCell";
static NSString *CellIdentifier = @"Custom Items Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *topLevelItems = [[UINib nibWithNibName:CellClassName bundle:[NSBundle mainBundle]] instantiateWithOwner:self options:nil];
cell = [topLevelItems objectAtIndex:0];
}
//... more irrelevant code here
}
请问有人能帮我吗?我已经在这个问题上工作了超过4个小时了。非常感谢!
附注:我正在使用ARC,并且正在开发iOS 5。
这是我的CustomCell.h文件。
#import <UIKit/UIKit.h>
@interface CustomCell : UITableViewCell{
UILabel *textLabel;
UILabel *detailTextLabel;
UIButton *starButton;
}
@property (strong, nonatomic) IBOutlet UILabel *textLabel;
@property (strong, nonatomic) IBOutlet UILabel *detailTextLabel;
@property (strong, nonatomic) IBOutlet UIButton *starButton;
@end
我的CustomCell.m文件里面没有内容。