单击导航栏上的按钮以获取更多导航控制器 - 无法推送视图控制器

发布于 2024-08-28 16:10:55 字数 2944 浏览 5 评论 0原文

好的,这是我的问题:我的应用程序在 iPhoneOS 屏幕底部的选项卡栏中显示类别。在显示“更多”按钮之前,仅允许 5 个类别。我有超过 25 个(请不要通过说:“重新考虑您的应用程序...等”来回答这个问题 - 这是之前粗鲁地说的。它们是食物、饮料等类别,无法更改)。我想让用户把他们最喜欢的东西放在主页上。由于编辑页面的空间限制,Apple moreNavigationController 编辑系统仅允许重新排列 20 个选项卡栏项目。这还不够,所以我需要实现我自己的编辑屏幕。我将 rightBarButtonItem 设置为 nil 并创建了我自己的。使用 NSLog,我可以看到单击“编辑”按钮时发生“单击”,但我无法使用 PushViewController 进行推送。什么也没发生。我认为这与我正在处理的 navigationController 有关......但我不确定。 ps:这一切都发生在我的应用程序代理中,它既充当 UITabBarControllerDelegate 又充当 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 的外观和感觉...但是当单击该按钮时,您无法退出该死的 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 是否具有与系统其他部分相冲突的特殊品质?

Okay, here is my issue: My app has a display of categories in the tab bar at the bottom of the iPhoneOS screen. This only allows 5 categories before it presents the MORE button. I have over 25 (please do not answer this by saying: "Rethink your application...etc" -- that was rudely said before. They are food, drink, etc categories and cannot be changed). I want to allow the user to put their favorites on the home page. The Apple moreNavigationController editing system only allows 20 tab bar items to be rearranged due to space constraints on the editing page. This is not enough so i need to implement my own Editing screen. I set the rightBarButtonItem to nil and created my own. Using NSLog, i can see the "click" happens when clicking the EDIT button, but I cannot push using pushViewController. Nothing happens. I think it has something to do with the navigationController I am addressing...but i am not sure. ps: This all happens in my App Delegate which DOES act as both UITabBarControllerDelegate & UINavigationControllerDelegate.

I tried to do the following:

 - ( 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];
 }


}

This works to place an EDIT button at the top right of the screen -- mimicking Apple's look and feel... but when that button is clicked, you cannot exit the darn moreNavigationController.

I have tried many things. UIAlerts work, etc...but pushing (or popping -- even popping to root view) a view controller on the stack does not.

- (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");

}

If you click the edit button on the moreNavigationController's display page, you get the log entries like expected AND (this is strange) the views on the stack climbs -- but no page change occurs. I marked it down to not using the correct navigation controller...but I am lost on how to find which one TO use.

this is a weird one too. In the edit function if i just do this:

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

It DOES take me home (to tabbarcontroller 0)

BUT doing this:

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

does not work.

Does the moreNavigationController have some special quality that screws with the rest of the system?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开雨落又逢春i 2024-09-04 16:10:56

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

您甚至可以编写 UITabBarController 的轻量级子类来为您处理此问题。

I would try reimplementing the whole "More" functionality from scratch. In other words, store the four home tabs in your user defaults and add a dummy fifth tab that switches to your own complete reimplementation of the more view controller stack.

You could even write a lightweight subclass of UITabBarController that handled this for you.

睫毛上残留的泪 2024-09-04 16:10:56

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

我已经成功拦截了shouldSelectViewController中的More Controller来更改数据源;您也许可以在那里找到一些解决方法。

PS 我倾向于同意您可以考虑重新设计您的应用程序,这样您就不需要将无限数量的 viewController 附加到选项卡栏只是为了选择类别;使用带有单个可滚动自定义视图的工具栏可能会更好。当然,如果这确实是为您的应用选择类别的最佳方式。

UITabBarController is evil, so I wouldn't be at all surprised if MoreController had some special properties, too.

I have had success intercepting the More Controller in shouldSelectViewController to change the data source; you may be able to find some workaround there.

PS I am inclined to agree that you could consider redesigning your app so that you didn't need an unlimited number of viewControllers attached to the tab bar just to select categories; you might have better luck using a tool bar with a single, scrollable, custom view in it. If that's really the best way of picking categories for your app, of course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文