我創建了一個單獨UITableViewCell
並使用.xib
文件設計它,它看起來像
[的UITableViewCell menuImage]:無法識別的選擇發送到實例0x10bb1e5e0
爲UITableViewCell
我的頭文件看起來像
@interface MenuTableViewCell : UITableViewCell
@property(nonatomic, weak) IBOutlet UIImageView *menuImage;
@property(nonatomic, weak) IBOutlet UILabel *menuLabel;
@end
和兩個屬性連接
我試圖用它在我MenuViewController
作爲
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.menuImage.image = [self getImageNameForRow:indexPath.row];
cell.menuLabel.text = self.features[(NSUInteger) indexPath.row];
return cell;
}
和
- (UIImage *)getImageNameForRow:(NSInteger)row {
if (row == 0) {
return [UIImage imageNamed:@"Transaction"];
}
if (row == 1) {
return [UIImage imageNamed:@"Summary"];
}
return [UIImage imageNamed:@"Budget"];
}
當我運行我的應用程序,它崩潰,並顯示在日誌
2014-08-30 14:51:54.387 pennyapp-ios[37988:70b] -[UITableViewCell menuImage]: unrecognized selector sent to instance 0x10bb1e5e0
2014-08-30 14:51:54.389 pennyapp-ios[37988:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell menuImage]: unrecognized selector sent to instance 0x10bb1e5e0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001023c6495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010212599e objc_exception_throw + 43
2 CoreFoundation 0x000000010245765d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001023b7d8d ___forwarding___ + 973
4 CoreFoundation 0x00000001023b7938 _CF_forwarding_prep_0 + 120
5 pennyapp-ios 0x00000001000044ed -[MenuTableViewController tableView:cellForRowAtIndexPath:] + 141
6 UIKit 0x0000000100904f8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
7 UIKit 0x00000001008ead5b -[UITableView _updateVisibleCellsNow:] + 2337
8 UIKit 0x00000001008fc721 -[UITableView layoutSubviews] + 207
9 UIKit 0x0000000100890993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
10 QuartzCore 0x0000000104fbc802 -[CALayer layoutSublayers] + 151
11 QuartzCore 0x0000000104fb1369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
12 QuartzCore 0x0000000104fb11ea _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x0000000104f24fb8 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
14 QuartzCore 0x0000000104f26030 _ZN2CA11Transaction6commitEv + 394
15 UIKit 0x0000000100848e25 _afterCACommitHandler + 128
16 CoreFoundation 0x0000000102391dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
17 CoreFoundation 0x0000000102391d37 __CFRunLoopDoObservers + 391
18 CoreFoundation 0x0000000102371522 __CFRunLoopRun + 946
19 CoreFoundation 0x0000000102370d83 CFRunLoopRunSpecific + 467
20 GraphicsServices 0x00000001036e3f04 GSEventRunModal + 161
21 UIKit 0x0000000100830e33 UIApplicationMain + 1010
22 pennyapp-ios 0x0000000100001353 main + 115
23 libdyld.dylib 0x00000001033655fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
下面我很新的iOS
和無法理解
錯誤信息,有人可以幫助我知道什麼是做錯了嗎?
您確定使用適當的CellIdentifier嗎?偶然,你忘了在IB中爲你的MenuTableViewCell指定它嗎? – heximal 2014-08-30 22:02:22
該錯誤清楚地表明'dequeue ...'返回'UITableViewCell'的實例,而不是'MenuTableViewCell'。你能向我們展示你的代碼部分,你在表格視圖中註冊了你的單元格類型嗎? – akashivskyy 2014-08-30 22:03:50
請參閱http://stackoverflow.com/questions/16637434/unrecognized-selector-sent-to-instance-when-using-custom-table-cell – danh 2014-08-30 22:58:24