简体   繁体   English

-[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x7fc748e37ea0'

[英]-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fc748e37ea0'

I'm busy making an app that loads a bunch of names from a .plist. 我正在忙着制作一个从.plist加载大量名称的应用程序。 I've set it up so that the .plist gets loaded into an UiTableView. 我已经进行了设置,以使.plist加载到UiTableView中。 Now the problem is that I get an error code whenever I try to open the menu that has the Table with the names in it. 现在的问题是,每当尝试打开带有名称表的菜单时,都会收到错误代码。

This is the error message: 这是错误消息:

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

This is my viewController.m 这是我的viewController.m

#import "ViewController.h"
#import "Stuff.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

Stuff *s = [[Stuff alloc] init];

[s getStuff];

self.items = [[NSMutableArray alloc] initWithArray:s.stuff];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath*)indexPath
{
NSString *id = @"plistdata";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id forIndexPath:indexPath];

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

cell.textLabel.text = self.items[indexPath.row];

return cell;
}


@end

Thanks! 谢谢!

To build on what Matt said: The error you are getting says that the UIViewController class (the base class of all view controllers) does not recognize the message tableView:numberOfRowsInSection: 根据Matt所说的:您得到的错误是UIViewController类(所有视图控制器的基类)无法识别消息tableView:numberOfRowsInSection:

Somehow when you're creating a view controller you're creating a generic UIViewController object instead of an instance of your custom ViewController class. 以某种方式在创建视图控制器时,将创建通用的UIViewController对象,而不是自定义ViewController类的实例。

The reason for this depends on how You're creating your view controller. 其原因取决于您如何创建视图控制器。

If you create it using code with a call to -[UIViewController initWithNibName:bundle:] , you may be creating an instance of UIViewController rather than your custom ViewController class: 如果使用调用-[UIViewController initWithNibName:bundle:]代码来创建它,则可能是在创建UIViewController的实例,而不是自定义的ViewController类:

ViewController *myVC = [[UIViewController alloc] initWithNibName: @ViewController" 
  bundle: nil];

If you're creating it using a storyboard, you may have the storyboard configured incorrectly. 如果使用情节提要创建它,则可能是情节提要配置不正确。

To help you figure out why you are getting a generic UIViewController instead of your custom class you'll need to tell us how you are creating an instance of your custom view controller. 为了帮助您弄清楚为什么要获得通用的UIViewController而不是自定义类,您需要告诉我们如何创建自定义视图控制器的实例。

The problem is that the code you have shown is never being called, because the view controller you've shown (ViewController) is not the table view's data source / delegate. 问题是您显示的代码永远不会被调用,因为您显示的视图控制器(ViewController)不是表视图的数据源/委托。 The data source / delegate messages are being sent to some other view controller. 数据源/委托消息被发送到其他视图控制器。 (This is probably because the storyboard is misconfigured, but you haven't given enough information for me to be sure of that.) (这可能是因为情节提要板配置错误,但是您没有提供足够的信息让我确定这一点。)

Verify that the File's Owner object in interface builder is set to be an instance of the UITableViewController subclass that you're implementing. 验证接口构建器中的“文件的所有者”对象是否设置为要实现的UITableViewController子类的实例。 Also make sure that the tableView outlet is linked to your table view. 还要确保tableView出口已链接到您的表视图。

.h file .h文件

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

Storyboard Setup 故事板设置

Attributes Inspector: 属性检查器:

在此处输入图片说明

Connections Inspector: 连接检查器:

在此处输入图片说明

暂无
暂无

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

相关问题 -[UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 - -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance [UIViewController tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 - [UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance tableview无法正常工作 - [UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例 - tableview not working - [UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance &#39;NSInvalidArgumentException&#39;-[UIViewController tableView:numberOfRowsInSection:]-无法识别的选择器已发送到实例 - 'NSInvalidArgumentException' - [UIViewController tableView:numberOfRowsInSection:] - unrecognized selector sent to instance [NSNull length]:无法识别的选择器发送到实例0x37fc8e48 iOS Swift - [NSNull length]: unrecognized selector sent to instance 0x37fc8e48 iOS Swift -[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x7ff437517770 - -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7ff437517770 无法识别的选择器已发送到实例0x7fc4e9544fc0 - unrecognized selector sent to instance 0x7fc4e9544fc0 tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 - tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 获取-[SearchViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例 - Getting -[SearchViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance -[用户长度]:无法识别的选择器已发送到实例0x7fc7b60143e0&#39; - -[User length]: unrecognized selector sent to instance 0x7fc7b60143e0'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM