tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

Read what the error message is telling you!

You have implemented numberOfRowsInSection:. So what? That's the wrong method. It is irrelevant. It will never be called.

The method you need to implement is called tableView:numberOfRowsInSection:. That's completely different.


I had delegate and datasource hooked up to the TableView

If you click on the view it should show the above connections in INSPECTOR. If you haven't got the ViewController hooked up as well you will get the error:

'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

How I stopped the error is you

  1. press on the ViewController to select it
  2. look for Referencing Outlets in the Connection inspector to the right
  3. drag from the circle of the New Referencing Outlet to the view
  4. when you release the mouse, a tiny popup will show - select datasource
  5. repeat step 3, and this time select delegate

When done, it should look like the image below!

Referencing outlet Datasource and delegate connected to view

This stopped the above error for me. I hope this helps someone.


Check if you have UITableViewDelegate, UITableViewDataSource defined in your class file:

class ClassName: UIViewController, UITableViewDelegate, UITableViewDataSource  
{

}