简体   繁体   English

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

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

I know this is dublicate question (and extremely sorry), but I've tried everything I've found on SO so far, but I am still receiving error this error: 我知道这是一个重复的问题(非常抱歉),但是到目前为止,我已经尝试了所有我发现的问题,但是仍然收到此错误的错误消息:

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

Let me clarify the parts clearly with images, so we can produce a good answer for solving related problem. 让我用图像清楚地阐明各部分,以便为解决相关问题提供一个很好的答案。

This is the folder view ( ViewController - main view, and TableView1 is child): 这是文件夹视图( ViewController主视图, TableView1是子视图):

在此处输入图片说明

My TableView1.xib file has: 我的TableView1.xib文件具有:

在此处输入图片说明 . 在此处输入图片说明

I have also edited my TableView1.swift : 我还编辑了TableView1.swift

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
      return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
}

In my Main.Storyboard : 在我的Main.Storyboard

When I select View Controller 当我选择View Controller 在此处输入图片说明 ( 在此处输入图片说明 ) it looks like this: )看起来像这样:

    1. 在此处输入图片说明
    1. 在此处输入图片说明

However, when I clicked on the View ( 但是,当我单击“ View 在此处输入图片说明 ): ):

    1. 在此处输入图片说明
    1. 在此处输入图片说明

What am I doing wrong or missing on the way? 我在路上做错了什么或想念什么?

More Info: 更多信息:

在此处输入图片说明

在此处输入图片说明

-[UIViewController tableView:numberOfRowsInSection:]:

So as per the error log you have somewhere type mismatch when you set deletegate and datasource.Its happening because on xib you say the tableview1.xib should implement datasource and delegate.But in ViewController1.swift you are mistakenly referencing to UIViewController. 因此,根据错误日志,在设置deletegate和datasource时,某处的类型不匹配,这是因为在xib上您说tableview1.xib应该实现数据源和委托。但是在ViewController1.swift中,您错误地引用了UIViewController。 now you see UIViewController is just unknown about implementing delegate and datasource.As it dont find (obviously) it crashes. 现在您看到UIViewController对于实现委托和数据源尚不为人所知,因为它没有(显然)崩溃。 so: 所以:

let controller : UIViewController = UIViewController(nibName: "TableView1", bundle: nil)

changed to: 变成:

let controller : UITableViewController = UITableViewController(nibName: "TableView1", bundle: nil)

should work. 应该管用。

Did you call this function else where? 您在其他地方调用过此功能吗?

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 10

} }

It looks like this function being called besides the delegate. 看起来除了委托以外,还调用了此函数。

No clue about Swift, but ObjC on iOS... 没有关于Swift的线索,但是iOS上的ObjC ...

The Exception says that the class UIViewController can't handle the message [UIViewController tableView:numberOfRowsInSection:]. 异常表明,类UIViewController无法处理消息[UIViewController tableView:numberOfRowsInSection:]。 This indicates, that at some point, the dataSource is changed to "super". 这表明,在某些时候,数据源已更改为“超级”。

Do you need the "override"? 您是否需要“替代”? You're not overriding a message implementation, since UIViewController doesn't implement one. 您不会覆盖消息的实现,因为UIViewController不实现一个。

暂无
暂无

声明:本站的技术帖子网页,遵循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 tableView:numberOfRowsInSection:]: 无法识别的选择器发送到实例 - tableView:numberOfRowsInSection:]: unrecognized selector sent to instance -[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x7ff437517770 - -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7ff437517770 -[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例0x7fc748e37ea0' - -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fc748e37ea0' 获取-[SearchViewController tableView:numberOfRowsInSection:]:无法识别的选择器已发送到实例 - Getting -[SearchViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance NSInvalidArgumentException:无法识别的选择器发送到实例 - NSInvalidArgumentException: unrecognized selector sent to instance NSInvalidArgumentException无法识别的选择器已发送到实例 - NSInvalidArgumentException unrecognized selector sent to instance 无法识别的选择器已发送到实例('NSInvalidArgumentException') - Unrecognized selector sent to instance ('NSInvalidArgumentException')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM