在我的 iPad 应用程序中,我有一个主菜单屏幕......上面有各种图标。
在点击图标时,它会将我导航到自定义 UISplitViewController。我用这段代码做到了。在 SplitView 中一切正常。
问题:我在点击 MASTER Viewcontroller 导航栏中的按钮时遇到返回主菜单屏幕的问题。
自定义 UIsplitview 的代码:-
self.navigationController.navigationBarHidden = NO;
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
left = [[LeftViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *leftNav = [[UINavigationController alloc] initWithRootViewController:left];
right = [[RightViewController alloc] initWithNibName:@"RightViewController" bundle:nil];
UINavigationController *rightNav = [[UINavigationController alloc] initWithRootViewController:right];
left.right = right;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNav,rightNav, nil];
splitViewController.delegate = right;
appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UISplitViewController *cvc = (UISplitViewController *) splitViewController;
[appDelegate.window setRootViewController:cvc];
编辑:自定义按钮代码
UIButton *a1 = [UIButton buttonWithType:UIButtonTypeCustom];
[a1 setFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[a1 addTarget:self action:@selector(menu:) forControlEvents:UIControlEventTouchUpInside];
[a1 setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
UIBarButtonItem *random = [[UIBarButtonItem alloc] initWithCustomView:a1];
left.navigationItem.leftBarButtonItem = random;
- (void)menu {
[self.view removeFromSuperview];
ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[appDelegate.window setRootViewController:vc];
[vc release];
}
这会导致 CRASH,并带有 EXC_BAD_ACCESS 消息。
请指导我..