如何使更多按钮始终更多视图?

时间:2013-03-27 09:33:21

标签: ios objective-c uitabbar

我正在使用Tab Bar为ios开发应用程序。我在酒吧有超过5个按钮,所以在iPhone上我有更多的按钮。 现在,假设我有这个按钮:Button1 Button2 Button3 Button4更多(和更多内部)Button5 Button6。 如果我单击更多,然后单击Button5,我将进入相对于Button5的视图。然后我单击Button2(不在更多),然后我进入相对于Button2的视图。 到现在为止还挺好。 现在如果我点击更多我不去更多选项卡但回到相对于Button5的视图。 如何使更多按钮始终更多地显示在视图中?

4 个答案:

答案 0 :(得分:1)

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

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

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

答案 1 :(得分:0)

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

对于Ex:

最初您有:Button1 Button2 Button3 Button4 Next

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

答案 2 :(得分:0)

我在我的app delegate.m中使用此代码来解决问题

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    UITabBarController* tabBarController2 = (UITabBarController*)self.window.rootViewController;
    if (tabBarController2.selectedIndex < 4) {
        [tabBarController2.moreNavigationController popViewControllerAnimated:NO];
    }
}

答案 3 :(得分: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代码,我尝试过,它的工作对我来说非常好。让我知道你在这方面遇到了什么问题。