T Davey
T Davey

Reputation: 1617

Universal app - Master Detail

I am a bit confused about something I hope someone could clarify for me. When I create a Universal Master Detail app, I notice that the tableview method didSelectRowAtIndexPath only deals with IPad selection.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
    self.detailViewController.detailItem = object;
}
}

Can someone tell me where the iPhone tableview selection is being handled.

Thanks in advance, Tim

Upvotes: 0

Views: 746

Answers (3)

T Davey
T Davey

Reputation: 1617

Thanks everyone for the suggestions. It turns out I had Core Data selected when I created the Universal App, however, I was not using Core Data properly. I have now leveraged Core Data and everything is working properly.

Upvotes: 0

nsgulliver
nsgulliver

Reputation: 12671

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

is checking & adding the data only for Ipad, you need to check for iphone also or remove this check so that it can work for all devices

in case you want to check for IPhone then use one of these ways

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 

or

if ([[UIDevice currentDevice] userInterfaceIdiom] ==UIUserInterfaceIdiomPhone)

Upvotes: 1

Ants
Ants

Reputation: 1338

Are you using storyboards? If so, then the tableView:didSelectRowAtIndexPath: is being handled via a segue with identifier @"showDetail".

So nothing is required in the table view delegate method.

If you turn off storyboards then you get this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        if (!self.detailViewController) {
            self.detailViewController = [[OCDDetailViewController alloc] initWithNibName:@"OCDDetailViewController_iPhone" bundle:nil];
        }
        self.detailViewController.detailItem = object;
        [self.navigationController pushViewController:self.detailViewController animated:YES];
    } else {
        self.detailViewController.detailItem = object;
    }
}

Which handles both iPhone and iPad cases.

Upvotes: 0

Related Questions