![](/img/trans.png)
[英]how do I make this pop up extension more generic to be applied to any view?
[英]How do i make the more button go always to more view?
我正在使用标签栏为ios开发一个应用程序。 我在栏上有5个以上的按钮,因此在iPhone上我有更多的按钮。 现在,假设我有以下按钮:Button1 Button2 Button3 Button4更多(和更多)内部Button5 Button6。 如果我单击“更多”,然后单击“ Button5”,则进入相对于“ Button5”的视图。 然后,我单击Button2(不在“更多”中),然后进入相对于Button2的视图。 到现在为止还挺好。 现在,如果单击“更多”,我将不转到“更多选项卡”,而是返回到相对于Button5的视图。 如何使更多按钮始终显示更多视图?
您不需要添加更多按钮。 只需将视图控制器设置为UITabBarController
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
如果您有5个以上的视图控制器,它将自动创建一个more按钮! 即NSArray的数量大于5。
您可以执行的另一种方法是,每当用户按下更多按钮时,第一个按钮将被删除,而其他按钮将被添加。 基本上,您可以创建一个数组并将所有按钮保留在其中。 然后基于所按下的按钮,您可以导航到该特定视图。
例如:
最初,您有: Button1
Button2
Button3
Button4
Next
:单击下一步之后Prev
Button3
Button4
Button5
Button6
我在我的应用程序委托.m中使用了此代码来解决问题
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UITabBarController* tabBarController2 = (UITabBarController*)self.window.rootViewController;
if (tabBarController2.selectedIndex < 4) {
[tabBarController2.moreNavigationController popViewControllerAnimated:NO];
}
}
- (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代码,我尝试过该代码,并且对我来说绝对可以正常工作。 让我知道您在这方面遇到什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.