单击导航栏上的按钮以执行moreNavigationController - 无法pushviewcontroller

时间:2010-04-09 16:54:45

标签: iphone uinavigationcontroller uitabbarcontroller pushviewcontroller

好的,这是我的问题:我的应用程序在iPhoneOS屏幕底部的标签栏中显示了类别。在呈现MORE按钮之前,这仅允许5个类别。我已经超过25岁了(请不要回答这个问题:“重新考虑你的申请......等等 - 这在以前是粗暴地说过。它们是食品,饮料等类别,不能改变)。我想允许用户将他们的收藏夹放在主页上。由于编辑页面上的空间限制,Apple moreNavigationController编辑系统仅允许重新排列20个标签栏项目。这还不够,所以我需要实现自己的编辑屏幕。我将rightBarButtonItem设置为nil并创建了我自己的。使用NSLog,我可以看到单击EDIT按钮时发生“单击”,但我无法使用pushViewController进行推送。什么都没发生。我认为它与我正在解决的navigationController有关...但我不确定。 ps:这一切都发生在我的App Delegate中,它同时充当UITabBarControllerDelegate& UINavigationControllerDelegate。

我尝试执行以下操作:

 - ( void )navigationController:( UINavigationController * )navigationController_local willShowViewController:( UIViewController * )viewController_local animated:( BOOL )animated
{

    UIViewController * currentController = navigationController_local.visibleViewController;
    UIViewController * nextController = viewController_local;

 // Do whatever here.
 NSLog(@"Nav contoller willShowViewController fired\n'%@'\n'%@'\nThere are currently: %d views on the stack\n",currentController,nextController,[self.navigationController.viewControllers count]);

 if ( [nextController isKindOfClass:NSClassFromString(@"UIMoreListController")])
 {
  UINavigationBar *morenavbar = navigationController_local.navigationBar;
  UINavigationItem *morenavitem = morenavbar.topItem;
  morenavitem.rightBarButtonItem = nil;
  NSLog(@"Is a UIMoreListController\n");

  UIBarButtonItem *editTabBarButton = [[UIBarButtonItem alloc]
             initWithTitle:@"Edit"
             style:UIBarButtonItemStylePlain
             target:self
             action:@selector(editTabBar:)];

  morenavitem.rightBarButtonItem = editTabBarButton;
  [editTabBarButton release];
 }


}

这可以在屏幕的右上角放置一个EDIT按钮 - 模仿Apple的外观......但是当点击该按钮时,你无法退出darn moreNavigationController。

我尝试了很多东西。 UIAlerts工作等...但是推送(或弹出 - 甚至弹出到根视图)堆栈上的视图控制器不会。

- (void) editTabBar:(id)sender {
 NSLog(@"clicked edit tabbar\n");
 NSLog(@"Total count of controllers: %d\n",[self.navigationController.viewControllers count]);

 TabBarViewController *tabBarViewController2 = [[TabBarViewController alloc] initWithNibName:@"TabBarView" bundle:nil];
  tabBarViewController2.navigationItem.title=@"Edit Tab Bar";
  [self.navigationController pushViewController:tabBarViewController2 animated:YES];
  [tabBarViewController2 release];

NSLog(@"finished edit tabbar\n");

}

如果单击moreNavigationController的显示页面上的编辑按钮,您将获得预期的日志条目和(这很奇怪)堆栈上的视图爬升 - 但不会发生页面更改。我把它标记为没有使用正确的导航控制器...但我迷失了如何找到使用哪一个。

这也是一个奇怪的。在编辑功能中如果我这样做:

- (void) editTabBar:(id)sender {
self.tabBarController.selectedIndex = 0;
}

它带我回家(对tabbarcontroller 0)

但这样做:

 - (void) editTabBar:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
    }

不起作用。

moreNavigationController是否具有与系统其余部分相关的特殊质量?

2 个答案:

答案 0 :(得分:2)

我会尝试从头开始重新实现整个“更多”功能。换句话说,将四个主页选项卡存储在用户默认值中,并添加一个虚拟的第五个选项卡,切换到您自己对更多视图控制器堆栈的完全重新实现。

你甚至可以编写一个UITabBarController的轻量级子类来为你处理这个问题。

答案 1 :(得分:0)

UITabBarController是邪恶的,所以如果MoreController也有一些特殊属性,我也不会感到惊讶。

我已成功拦截shouldSelectViewController中的更多控制器以更改数据源;你可以在那里找到一些解决方法。

PS我倾向于同意您可以考虑重新设计您的应用,这样您就不需要连接到标签栏的无限数量的viewControllers来选择类别;使用带有单个可滚动自定义视图的工具栏可能会有更好的运气。当然,如果这是为您的应用选择类别的最佳方式。