Xcode TableView - 无法识别的选择器发送到实例

时间:2012-06-19 01:45:14

标签: ios xcode uitableview storyboard

我正在尝试学习表格视图,但我遇到了麻烦。我在Storyboard中正确连接了视图委托和数据源,但是当我到达包含表视图的应用程序部分时,我收到以下运行时错误。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationItem tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

这是我的实现文件中的块

@implementation CraftingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    }

    cell.textLabel.text = @"Detail";

    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

2 个答案:

答案 0 :(得分:1)

正在显示该错误消息,因为tableView:numberOfRowsInSection:被发送到UINavigationItem类型的对象,而您的CraftingViewController类似乎可能是UITableViewController类型。我会确保您已将代理连接到正确的类,因为CraftingViewController似乎没有正确连接。

答案 1 :(得分:-1)

如果数据源是nib文件的控制器。

请检查此控制器的alloc使用“CraftingViewController”而不是“UIViewController”

相关问题