Question

I have a universal application that is very basic. It is a master detail. When I segue from the master to the detail, I set the text in a label, and set the title of the destination view controller with an NSString. This works fine on iPhone, but on iPad, it doesn't set the title or the label. Here is the code I am using to set everything:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSString *object = dailyGramsNumbers[indexPath.row];
        NSString *object1 = dailyGramsBody [indexPath.row];
        [[segue destinationViewController] setDetailItem:object1];
        [[segue destinationViewController] setTitle:object];

    }
}

thanks for any help!

here is the code I am using now (in addition to the above code):

- (void)tableView:

    (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            NSString *object = dailyGramsNumbers[indexPath.row];
            [self.splitViewController.viewControllers[1] setTitle:object];

            self.detailViewController.detailItem = object;
        }
    }
Was it helpful?

Solution

A split view controller has a viewControllers property, and the controller at index 1 will be the detail controller. So, you can accomplish the same task on the iPad version by putting in this code,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *object = dailyGramsNumbers[indexPath.row];
    NSString *object1 = dailyGramsBody[indexPath.row];
    [self.splitViewController.viewControllers[1] setDetailItem:object1];
    [self.splitViewController.viewControllers[1] setTitle:object];
}

You should import the DetailController.h file into the .m file of the master controller, and you might have to cast self.splitViewController.viewcontrollers[1] to your detail controller class.

After Edit:

If the detail controller is embedded in a navigation controller, code like this should work,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *object = dailyGramsNumbers[indexPath.row];
    NSString *object1 = dailyGramsBody[indexPath.row];
    [(DetailViewController *)[self.splitViewController.viewControllers[1] topViewController] setDetailItem:object1];
    [(DetailViewController *)[self.splitViewController.viewControllers[1] topViewController] setTitle:object];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top