Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get master view controller in detail view controller with UISplitViewController?

I have a UISplitViewController with master controller and detail controller:

MyMasterController *masterViewController = [[[MyMasterController alloc] initWithDirectory:directoryElement] autorelease];
MyDetailController *detailViewController = [[MyDetailController alloc] init];

masterViewController.detailViewController = detailViewController;

UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = @[[[UINavigationController alloc] initWithRootViewController:masterViewController], [[UINavigationController alloc] initWithRootViewController:detailViewController]];
splitViewController.delegate = self; 

The MyDetailController is a table list view controller, I want to master view controller run one method when user clicks on cell, So how to get the master controller in detail controller ?

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   [master some_method]; // how to get ?
} 
like image 997
why Avatar asked Mar 05 '13 07:03

why


1 Answers

I would use notifications instead, so in your master:

-(void) viewDidLoad {

    ...
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod) name:@"DoSomeMethod" object:nil];

}

-(void) someMethod {

    ...

}

And in your detail:

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

   [[NSNotificationCenter defaultCenter] postNotificationName:@"DoSomeMethod" object:nil];

} 
like image 71
jjv360 Avatar answered Nov 08 '22 16:11

jjv360