SplitViewController委托方法没有响应

时间:2011-12-14 07:22:12

标签: iphone objective-c ios uisplitviewcontroller uisplitviewdelegate

我在视图控制器上添加了拆分视图控制器,如下所示:

rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
rootViewController.detailViewController = detailViewController;

splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, detailViewController, nil];
splitViewController.delegate = detailViewController;

[self.view addSubview:splitViewController.view];

但是,在DetailViewController中定义的这个方法永远不会被调用:

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc 

如果我在splitviewcontroller中设置window,则会调用此方法! 任何建议?

2 个答案:

答案 0 :(得分:1)

请确保您的DetailViewController类实现UISplitViewControllerDelegate协议。

答案 1 :(得分:1)

我知道splitViewController不能是任何其他视图的子视图,因此splitViewController必须始终是mainViewController。