[UITableViewCell menuImage]:无法识别的选择器发送到实例0x10bb1e5e0

时间:2014-08-30 21:58:01

标签: ios objective-c iphone uitableview

我创建了一个单独的UITableViewCell并使用.xib文件设计它,它看起来像是 enter image description here

UITableViewCell的头文件看起来像

@interface MenuTableViewCell : UITableViewCell
@property(nonatomic, weak) IBOutlet UIImageView *menuImage;
@property(nonatomic, weak) IBOutlet UILabel *menuLabel;
@end  

并且两个属性都已连接
enter image description here enter image description here 我尝试在我的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不熟悉并且无法理解错误消息,有人可以帮助我知道我做错了什么吗?

2 个答案:

答案 0 :(得分:4)

有2个问题。

  1. 我正在注册UITableViewCell而不是MenuTableViewCell
  2. 我没有注册我拥有的nib文件
  3. 按照以下方式进行更改后,再次开始工作。

    [self.tableView registerNib:[UINib nibWithNibName:@"MenuTableViewCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    

    感谢您的所有答案,他们帮助了我很多!

答案 1 :(得分:0)

在接口中声明一个imgearray,然后添加你的图像数组,下一个cellforatindexpath为UIImageView添加代码 yourcellname.yourimagename.image = [UIImage imagenamed:[yourimagearray objectAtIndexPath.row]];