UITableView woes: Keep on getting this runtime err

2020-03-04 12:07发布

HI guys,

I have this error that is keeping me from moving forward. I basically have an application which contains a UITabViewController which points to individual UIViewControllers. So one of the tabs, I want to implement a basic TableViewController.

Now, no matter what i do, whether its cut and paste sample UIViewController code that implements a UITableView, or whatever, or even just the default UITableViewController template from Xcode, i get the same error below:

2009-09-06 12:29:23.889 iKosher[12536:207] * -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xe1d8d0 2009-09-06 12:29:23.891 iKosher[12536:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xe1d8d0' 2009-09-06 12:29:23.891 iKosher[12536:207] Stack: ( 807902715, 2492915529, 808284155, ...

In IB, all I have done is drag onto the view a UITableView and set its delegates to point to the file owner.

Not sure what else i can do from here

4条回答
够拽才男人
2楼-- · 2020-03-04 12:41

It looks like your code is sending a tableView:numberOfRowsInSection: message to a UIViewController instance. I think it should be sending that message to an object that implements the UITableViewDataSource protocol.

Check your implementation file for the UITableViewController you are using to make sure it has the tableView:numberOfRowsInSection: method implemented (or uncommented, depending on how you generated the file).

If you have any code, post it.

查看更多
贼婆χ
3楼-- · 2020-03-04 12:41

I ran into this problem, the key was changing class identity in Interface Builder.

查看更多
时光不老,我们不散
4楼-- · 2020-03-04 13:00

Make sure that the File's Owner object in IB is set to be an instance of the UITableViewController subclass that you're implementing, and that it has a tableView outlet that's linked to your table view.

查看更多
干净又极端
5楼-- · 2020-03-04 13:05

The issue for me was not setting the up the UITableView delegate and datasource properly.

I had these hooked up to the UITableView on my ViewController, but what I really needed was both of these hooked up to the 'Files Owner' (note I am working with xibs not storyboards).

I found the whole process to be confusing and a lot of work.

I wrote up my experiences about it here.

查看更多
登录 后发表回答