2
我在iOS6設備上運行時遇到崩潰,但不是iOS 7設備時崩潰。我有一個自定義UITableViewCell
與xib LanguageCell.xib。它有2個標籤,一個按鈕和一個視圖。我有一個類LanguageCell在那裏我有4個IBOutlets:iOS6崩潰:此類不是密鑰編碼兼容密鑰
@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上?
編輯: 我要補充的是,自定義類設置正確的廈門國際銀行
編輯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個其他表使用相同的確切代碼,它工作得很好。我不明白爲什麼這個會給我帶來麻煩。
您是否嘗試清潔該項目? 'Shift + CMD + K' – hgwhittle
是的。清理,清理生成文件夾,刪除派生數據,關閉Xcode,從手機中刪除應用程序等等。沒有任何工作:( –
故事板有時可能會損壞,請嘗試清除IB中的連接,保存並重新創建它 –