首先,对不起我的英语。我正在尝试使用导航控制器为iPad执行应用程序,该应用程序在选择“ Next”按钮时将视图控制器按下。但我也想要一个弹出框,从导航栏中的按钮调用,允许用户从一个视图控制器“跳转”到另一个视图控制器,使用 tableView:didSelectRowAtIndexPath: 和 pushViewController:animated: 方法推送它,但是它不工作。
概括:
标签栏-> 在 FirstViewController 和 SecondViewController 之间切换(工作得很好)
导航栏(按钮 Next) -> 在 SecondViewController、FirstSlideController 和 SecondSlideController 之间切换(也不错)
Popover -> 用户选择 SecondViewController、FirstSlideController 或 SecondSlideController(这就是问题所在!)
代码:
应用委托
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[navigationController1, navigationController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
TableViewController(popover) 的 didSelectRowAtIndexPath 方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0){
FirstSlideController *detailViewController = [[FirstSlideController alloc] initWithNibName:@"FirstSlideController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
else if(indexPath.row == 1){
SecondSlideController *detailViewController = [[SecondSlideController alloc] initWithNibName:@"SecondSlideController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
else{
SecondViewController *detailViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
}
SecondViewController(使用 maros 建议的委托)
-(void) showPopover:(id) sender
{
TableViewController *PopoverView = [[TableViewController alloc] initWithNibName:@"TableViewController" bundle:nil];
self.popOver = [[UIPopoverController alloc] initWithContentViewController:PopoverView];
self.popOver.delegate = self;
[self.popOver presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedArrowDirections: UIPopoverArrowDirectionUp animated: YES];
}
我试图打印 self.navigationController 它说它是空的。我会很感激任何帮助。
谢谢你。