0

我正在为带有标签栏的 ios 开发应用程序。我在栏上有超过 5 个按钮,所以在 iphone 上我有更多的按钮。现在,假设我有这个按钮: Button1 Button2 Button3 Button4 More(和内部更多) Button5 Button6。如果我单击更多,然后单击 Button5,我将进入相对于 Button5 的视图。然后我单击 Button2(不在“更多”中)并进入相对于 Button2 的视图。到目前为止,一切都很好。现在,如果我单击更多,我不会转到更多选项卡,而是返回相对于 Button5 的视图。我如何使更多按钮始终转到更多视图?

4

4 回答 4

1

您无需添加更多按钮。只需将视图控制器设置为 UITabBarController

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

如果您有超过 5 个视图控制器,它将自动创建一个更多按钮!即 NSArray 的计数大于 5。

于 2013-03-27T10:38:10.013 回答
0
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[UIViewController alloc] init];
    UIViewController *viewController2 = [[UIViewController alloc] init];
    UIViewController *viewController3 = [[UIViewController alloc] init];
    UIViewController *viewController4 = [[UIViewController alloc] init];
    UIViewController *viewController5 = [[UIViewController alloc] init];
    UIViewController *viewController6 = [[UIViewController alloc] init];
    UIViewController *viewController7 = [[UIViewController alloc] init];
    UIViewController *viewController8 = [[UIViewController alloc] init];
    UIViewController *viewController9 = [[UIViewController alloc] init];

    [viewController1.view setBackgroundColor:[UIColor whiteColor]];
    [viewController2.view setBackgroundColor:[UIColor redColor]];
    [viewController3.view setBackgroundColor:[UIColor greenColor]];
    [viewController4.view setBackgroundColor:[UIColor grayColor]];
    [viewController5.view setBackgroundColor:[UIColor blueColor]];
    [viewController6.view setBackgroundColor:[UIColor yellowColor]];
    [viewController7.view setBackgroundColor:[UIColor brownColor]];
    [viewController8.view setBackgroundColor:[UIColor magentaColor]];
    [viewController9.view setBackgroundColor:[UIColor purpleColor]];

    [viewController1 setTitle:@"one"];
    [viewController2 setTitle:@"two"];
    [viewController3 setTitle:@"three"];
    [viewController4 setTitle:@"four"];
    [viewController5 setTitle:@"five"];
    [viewController6 setTitle:@"six"];
    [viewController7 setTitle:@"seven"];
    [viewController8 setTitle:@"eight"];
    [viewController9 setTitle:@"nine"];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4, viewController5, viewController6, viewController7, viewController8, viewController9];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

我添加了一个我尝试过的示例 AppDelegate 代码,它对我来说绝对没问题。让我知道你在这方面遇到了什么问题。

于 2013-03-28T09:31:33.763 回答
0

我在我的应用程序 delegate.m 中使用了这段代码来解决问题

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    UITabBarController* tabBarController2 = (UITabBarController*)self.window.rootViewController;
    if (tabBarController2.selectedIndex < 4) {
        [tabBarController2.moreNavigationController popViewControllerAnimated:NO];
    }
}
于 2013-03-28T08:24:48.630 回答
0

您可以做的另一种方法是,每当用户按下更多按钮时,第一个按钮就会被删除,而其他按钮会被添加。基本上,您可以创建一个数组并将所有按钮保留在其中。然后根据按下的按钮,您可以导航到该特定视图。

例如:

最初你有: Button1 Button2 Button3 Button4 Next

点击下一步后:Prev Button3 Button4 Button5 Button6

于 2013-03-27T10:05:59.873 回答