App认为class是UITableViewLabel

时间:2015-11-05 22:04:18

标签: ios unrecognized-selector

我正在创建一个使用类对象MyObject(下面的界面)的iOS应用程序:

#import <Foundation/Foundation.h>

@interface MyObject : NSObject

@property (nonatomic, copy) NSString *address;

我创建了一个名为object的对象:

@class MyObject;

@interface DetailViewController : UITableViewController

@property (strong, nonatomic) MyObject *object;

我在另一个类的prepareForSegue方法中初始化了该对象:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        DetailViewController *detailViewController = [segue destinationViewController];

        detailViewController.object = [self.dataController objectInMasterListAtIndex:[[self.tableView indexPathForSelectedRow]row]];
    }
}

之后,我在此代码中访问object的属性:

- (void)configureView {
    // Update the user interface for the detail item.
    if (self.object) {
        self.address.text = self.object.address;
    }
}

当我运行它时,我收到了这个意外错误:

2015-11-05 14:51:00.939 TestApp[26277:2153527] -[UITableViewLabel address]: unrecognized selector sent to instance 0x7b6d6300

此错误指向我访问该属性的行。

如您所见,self.object显然不是UITableViewLabel,因为错误说明了。 address绝对是MyObject类的对象(我已经检查过了。)

1 个答案:

答案 0 :(得分:0)

我明白了。问题是我初始化对象的函数(称为configureView())没有被首先声明。现在一切似乎都还行。谢谢rmaddy和JAL帮助我找到这个问题。