views:

3508

answers:

5

I'm writing an iPhone app with a table view inside a tab view. In my UITableViewController, I implemented -tableView:didSelectRowAtIndexPath:, but when I select a row at runtime, the method isn't being called. The table view is being populated though, so I know that other tableView methods in my controller are being called.

Does anyone have any ideas what I may have screwed up to make this happen?

+4  A: 

It sounds like perhaps the class is not the UITableViewDelegate for that table view, though UITableViewController is supposed to set that automatically.

Any chance you reset the delegate to some other class?

Hunter
I discovered that while my controller was a UITableViewController, I used a plain old UIViewController widget in UI Builder. That doesn't work. When I deleted the UIViewController widget and dropped a UITableViewController in its place, everything worked.
Matt Pfefferle
A: 

I have encountered two things in this situations.

  1. You may have forgot to implement UITableViewDelegate protocol, or there's no delegation outlet between your class and your table view.

  2. You might have a UIView inside your row that is a first responder and takes your clicks away. Say a UIButton or something similar.

gilm
+1  A: 

Hi, I know is old and the problem was resolved, but a had similar problem, I thought that the problem was with my custom UITableViewCell, but the solution was completely different - I restart XCode :) and then works ok ! almost like Windows :)

A: 

I had this problem myself. I had built the bones of the view in IB (just a View and a TableView) and the delegate wasn't set. I wired it up to File's Owner and it worked like a charm. ::save::

indigosplinter
A: 

Hi everyone.

I have had the same problem. And it was hard to find. But somewhere in my code was this:

  • (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { return nil; }

It must be "return indexPath", else -tableView:didSelectRowAtIndexPath: is not being called.

Greetings

Jack

JackPearse