我正在尝试将一个视图控制器推入一个nowmodal但没有任何事情发生。所以,我有一个loginController作为rootViewController,它推送一个tabBarControler,然后在tabBar视图中打开一个presentModal。在presentModal中我有一个UITableView,当点击推另一个视图但是当我尝试这样做时没有任何反应。为了更清楚,这里是层次结构:
LoginViewController(作为根视图控制器)>>> push>>> UITabBarController(HomeViewController和另外两个)>>>打开>>> PackViewController(presentModal)需要通过pushViewController打开另一个视图:
代码:
AppDelegate.m
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
LoginViewController_iPhone *loginViewController = [[LoginViewController_iPhone alloc] init];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:loginViewController] autorelease];
self.window.rootViewController = self.navigationController;
LoginViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
HomeViewController_iPhone *referenciaHomeViewController = [[HomeViewController_iPhone alloc] init];
MapaViewController_iPhone *referenciaMapaViewController = [[MapaViewController_iPhone alloc] init];
GuiaViewController_iPhone *referenciaMidiaViewController = [[GuiaViewController_iPhone alloc] init];
UINavigationController *navHome = [[UINavigationController alloc] initWithRootViewController:referenciaHomeViewController];
UINavigationController *navMapa = [[UINavigationController alloc] initWithRootViewController:referenciaMapaViewController];
UINavigationController *navGuia = [[UINavigationController alloc] initWithRootViewController:referenciaMidiaViewController];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tabBarBackground"]];
[self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"tabBarSelected"]];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navHome, navMapa, navGuia, nil];
}
- (void)login {
[self.navigationController pushViewController:self.tabBarController animated:YES];
}
PackViewController.m(PRESENTMODAL):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
CompraPackViewController_iPhone *controller = [[CompraPackViewController_iPhone alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
答案 0 :(得分:2)
执行当前模态时,需要提供一个导航控制器,其根视图控制器是表视图控制器。