我在iOS6设备上运行时遇到了崩溃但不是iOS 7设备。我有一个带有xib LanguageCell.xib的自定义UITableViewCell
。它有2个标签,一个按钮和一个视图。我有一个LanguageCell类,我有4个IBOutlets:
@interface LanguageCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *titleLbl;
@property (strong, nonatomic) IBOutlet UIButton *buyButton;
@property (strong, nonatomic) IBOutlet UILabel *saleLbl;
@property (strong, nonatomic) IBOutlet UIView *separatorLine;
我已将所有4个视图连接到其属性,因此连接窗格如下所示:
当我运行应用程序时,加载此表时出现崩溃:
*** Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<LanguageCell 0x1f5160c0> setValue:forUndefinedKey:]: this class
is not key value coding-compliant for the key buyButton.'
为什么我在iOS6上遇到此问题而不是iOS7?
修改 我应该补充说,在xib上正确设置了自定义类
编辑2:
当我清除所有IB连接并运行代码时,行if ([currentObject isKindOfClass:[LanguageCell class]])
在应该为真时返回false,因此cell
仍为nil
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
LanguageCell *cell = (LanguageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LanguageCell" owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[LanguageCell class]])
{
cell = (LanguageCell *)currentObject;
break;
}
}
}
我在我的应用程序中为其他3个表使用相同的确切代码,它运行正常。我不明白为什么这个给我带来了问题。
答案 0 :(得分:3)
我有完全相同的问题。如果您将Interface Builder
内的元素与不再存在的方法相关联,通常会发生这种情况。
我也使用了相同的类名。更改名称后,即使在iOS 6.0
上,一切也都适用于我。