3
votes

I created a universal master-detail application. I have a table view within a custom class (MasterViewController class). This is a UITableViewController class. Using Storyboard, I created a custom cell in my iPhone table view. The custom cell contains 3 labels and 1 image. In StoryBoard, this table view datasource and delegate is set to the MasterViewController class. My custom table view cell has 'User Interaction Enabled' in the View section of the attribute inspector. In my MasterViewController class, the UITableViewDataSource methods such as 'numberOfSectionsInTableView' are working fine. I have a seque defined between the table view and a detailed view. When I run the application and select a cell in the table view, the didSelectRowAtIndexPath is not called for the iPhone. My prepareForSegue method executes and the segue occurs.

I have read quite a number of posts on didSelectRowAtIndexPath not being executed, but I have not been able to solve my problem.

Any hints would be very much appreciated.

My custom cell identifier is ConversationCell. The segue identifier is ShowConversationDetails. I debug with a breakpoint on the first line of numberOfRowsInSection and this method is never entered.

The segue works and the detail view displays my label with 'Hello' text.

Some Code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];

//NSLog(@"Rows %lu",(unsigned long)[sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"ConversationCell";

UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

[self configureCell:cell atIndexPath:indexPath];

return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {


   [[self.fetchedResultsController sections] count]);


   NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
    self.detailViewController.detailItem = object;
}
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowConversationDetails"]) {

    NSIndexPath *selectedIndex = [self.tableView indexPathForSelectedRow];

    Event *e = nil;

    e = [self.fetchedResultsController objectAtIndexPath:selectedIndex];

    UIViewController *destinationViewController = [segue destinationViewController];
    [segue.destinationViewController setLabel:@"Hello"];
    }
}

MASTERVIEWCONTROLLER: Here is my interface for above;

@interface MasterViewController : UITableViewController     <NSFetchedResultsControllerDelegate,ASIHTTPRequestDelegate,UITableViewDelegate, UITableViewDataSource>
{
NSMutableArray *eventsArray;

}

This may be a clue to my problem. When I add the following code to prepareForSeque

NSIndexPath *selectedIndex = [self.tableView indexPathForSelectedRow];
    NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:selectedIndex];
    NSString *messageTableID = [[object valueForKey:@"messagetableid"] description];

selectedIndex is empty as if a row is no longer selected when prepareForSeque is executing.

By the way, just to be safe, I removed the app from the simulator and then did a Clean on the project and nothing changed.

Tim

3
Well Well Well, I suspect your cell - 'ConversationCell' has a view which is on top and doesn't letting the touches passing through it to the table view cell. If you are getting into cellforRow, HeightForRowAtIndex etc methods and you are saying that you are having trouble with DidSelectRowAtIndexPath then it has to be due to the topmost view, it isn't letting the touches pass through to the cell. All you can do is, just set the 'SetUserInterActionEnabled:NO' to the views you have it on table view cell and then test it by tapping on row. DO NOT TURN OFF Interaction for the Cell. Cheers. :)Reno Jones
Reno, thanks for the tip. I had neglected to mention that I deselected 'User Interaction Enabled' for each of the elements of my custom cell. The interaction for the custom cell remains on. Unfortunately, with all that done, DidSelectRowAtIndexPath is not called.T Davey
Remove all views or setHidden:TRUE for all views on your xib file of Cell, and then try and build to see if you could manage to get the touches or not?Reno Jones

3 Answers

3
votes

In addition to the checks you have already mentioned, here are a few other ones you might want to consider:

Check that the method is exactly this (no difference in letter cases) :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Check that the controller implements the UITableViewDelegate protocol

Check that interaction does work (change the selection style option so that the cell changes color on touch events)

Check that you don't have any view inside that is first responder and takes away the interaction (remove any view in the cell to test)

Try to programmatically allow selection on the table [tableView setAllowsSelection:YES];

0
votes

Are you sure that your UITableViewDelegate object is correctly being set as the table view's delegate? (This is separate from setting it as the data source.)

0
votes

I ended up deleting my MasterViewController and DetailViewController. I recreated them and things are now working. Not sure what I did wrong the first time. Thanks for everyone that offered advice. Tim