我有一个UISplitViewController主控制器和细节控制器:
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;
Run Code Online (Sandbox Code Playgroud)
该MyDetailController是表列表视图控制器,我想掌握视图控制器运行的一种方法,当用户单击单元格,那么如何获得详细控制器主控制器?
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[master some_method]; // how to get ?
}
Run Code Online (Sandbox Code Playgroud)
jjv*_*360 15
我会使用通知,所以在你的主人:
-(void) viewDidLoad {
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod) name:@"DoSomeMethod" object:nil];
}
-(void) someMethod {
...
}
Run Code Online (Sandbox Code Playgroud)
在你的细节:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[NSNotificationCenter defaultCenter] postNotificationName:@"DoSomeMethod" object:nil];
}
Run Code Online (Sandbox Code Playgroud)