简体   繁体   English

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

[英]Xcode TableView - unrecognized selector sent to instance

I'm trying to learn table views and I've hit a snag. 我正在尝试学习表格视图,但遇到了麻烦。 I have the view delegate and datasource connected correctly in Storyboard, but I get the following runtime error when I get to the section of my app containing the table view. 我已经在Storyboard中正确连接了视图委托和数据源,但是当我到达包含表视图的应用程序部分时,出现以下运行时错误。

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

Here's the chunk from my implementation file 这是我的实现文件中的块

@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 {

}

That error message is displaying because tableView:numberOfRowsInSection: is being sent to an object of type UINavigationItem while it seems like your CraftingViewController class is probably of type UITableViewController . 之所以显示该错误消息,是因为tableView:numberOfRowsInSection:被发送到UINavigationItem类型的对象,而您的CraftingViewController类可能是UITableViewController类型。 I would make sure that you have connected your delegate to the correct class, because it doesn't seem like CraftingViewController is connected properly. 我将确保您已将委托连接到正确的类,因为CraftingViewController似乎未正确连接。

if the datasource is controller of the nib file. 如果数据源是nib文件的控制器。

please check alloc of this controller use "CraftingViewController" not "UIViewController" 请检查此控制器的分配使用“ CraftingViewController”而不是“ UIViewController”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 xcode - 发送到实例的无法识别的选择器 - xcode - unrecognized selector sent to instance Xcode“无法识别的选择器已发送到实例” - Xcode “unrecognized selector sent to instance” 无法识别的选择器已发送到实例XCODE - unrecognized selector sent to instance XCODE [ComponentTaleView tableView:heightForFooterInSection:]:无法识别的选择器已发送到实例 - [ComponentTaleView tableView:heightForFooterInSection:]: unrecognized selector sent to instance tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 - tableView:numberOfRowsInSection:]: unrecognized selector sent to instance TableView在reloadData上崩溃 - '无法识别的选择器发送到实例' - TableView Crashes on reloadData - 'unrecognized selector sent to instance' [UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 - [UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 无法识别的选择器已发送到实例tableview swift - Unrecognized selector sent to instance tableview swift 填充Tableview时将无法识别的选择器发送到实例 - unrecognized selector sent to instance when populating a Tableview -[UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 - -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM