ace*_*des 9 iphone xcode objective-c uitableview
我在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.'
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用nibname加载自定义表格视图单元格:@"CustomCell".它的类被分配给"CustomCell"(与nib名称相同的类名).它的文件所有者也设置为加载这些单元格的类 - "ProductsTableViewControllerWithSearch".笔尖中的所有插座都连接到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
}
Run Code Online (Sandbox Code Playgroud)
请有人帮帮我.我已经工作了4个多小时.非常感谢!
PS:我正在使用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
Run Code Online (Sandbox Code Playgroud)
我的CustomCell.m中没有任何内容
小智 13
如果要链接任何不属于该视图的内容,则会发生此错误.
在这种情况下,解决方案是在Interface Builder中
而已.
在Interface Builder中,您需要将单元格的类设置为CustomCell,而CustomCell需要具有属性title
.
this class is not key value coding-compliant for the key …
通常意味着在类上找不到属性,Interface Builder正在尝试使用该属性,从而导致崩溃.
我假设您在运行时从NIB加载单元格时出现此错误.(如果相反它会打破你编写的某些代码行,为了上帝的缘故,删除那行代码!)
进入您的自定义单元格的XIB视图,按住Ctrl键单击"文件所有者",然后取消链接您在那里所谓的"标题"连接.如果你感觉很精神,取消所有内容的链接,那么重新链接你想要的东西.看看是否清除它.如果不是,我会在这里待几个小时.
归档时间: |
|
查看次数: |
7953 次 |
最近记录: |