【问题标题】:PushViewController with tabBarController not working带有 tabBarController 的 PushViewController 不起作用
【发布时间】:2013-06-25 17:26:53
【问题描述】:

我有一个 tabBar 应用程序。其中一个选项卡有一个 rootviewcontroller,它创建一个 UITableView 并将其添加到子视图中。当用户单击 UITableView 中的单元格时,我想推送一个新的 rootviewcontroller,但我无法让它工作。

在我的 appDelegate 中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
    //Create the window
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    //Create the UIViewCOntrollers for each tab
    _viewController1 = [[[LocavoreRetroFirstViewController alloc] initWithNibName:@"LocavoreRetroFirstViewController" bundle:nil] autorelease];
    _viewController2 = [[[LocavoreRetroSecondViewController alloc] initWithNibName:@"LocavoreRetroSecondViewController" bundle:nil] autorelease];
    UIViewController *viewController3 = [[[LocavoreRetroThirdViewController alloc] initWithNibName:@"LocavoreRetroThirdViewController" bundle:nil] autorelease];
    _viewController4 = [[[LocavoreRetroFourthViewController alloc] initWithNibName:@"LocavoreRetroFourthViewController" bundle:nil] autorelease];
    UIViewController *viewController5 = [[[LocavoreRetroFifthViewController alloc] initWithNibName:@"LocavoreRetroFifthViewController" bundle:nil] autorelease];


    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController1];
    //[_viewController1 release];

     NSArray* controllers = [NSArray arrayWithObjects:navigationController, _viewController2, viewController3, _viewController4, viewController5, nil];

    //Create the tab controller
    _tabBarController = [[[UITabBarController alloc] init] autorelease];
    [_tabBarController setViewControllers:controllers];


    //Initialize the tab controller with the views
//    _tabBarController.viewControllers = @[_viewController1, _viewController2,
//    viewController3, _viewController4, viewController5];

    //Set the window to the tabcontroller view and make it visible
    _window.rootViewController = _tabBarController;
    _tabBarController.delegate=self;
    [_window makeKeyAndVisible];

    return YES;
}

在我的子视图中 didSelectRowAtIndexPath 方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{   

    RecipePageController *recipePageController = [[RecipePageController alloc] initWithNibName:@"RecipePageController" bundle:nil];

    [self.navigationController pushViewController:recipePageController animated:YES];
    [recipePageController release];

}

【问题讨论】:

  • is..this..peice..of..code..is..in..viewcontroller1?
  • @AlokSingh 请在单词之间使用空格而不是两个句点。不要像 William Shatner 那样打字。
  • 哪个标签有问题?正如您现在所拥有的,只有第一个选项卡位于导航控制器中。
  • 在..my..keyboard..space..is..not..working
  • viewController4 不工作,但我将它添加到一个新的导航控制器。谢谢

标签: ios uinavigationcontroller pushviewcontroller tabbarcontroller


【解决方案1】:

您需要为每个选项卡创建一个单独的导航控制器

【讨论】:

  • 考虑使用虚拟键盘。或者复制/粘贴空格来替换双点。
  • 我为 _viewController4 创建了一个视图控制器,现在它可以工作了。非常感谢。
猜你喜欢
  • 2013-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-13
  • 2014-01-24
  • 1970-01-01
相关资源
最近更新 更多