xcode 从 UINavigationController 推送 UITabBarController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6624283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Push UITabBarController from UINavigationController
提问by jorjap
I have a UINavigationControllerand I am navigating from one view to another successfully. But at some point I want to show a UITabBarControllerwith some views.
我有一个UINavigationController并且我正在成功地从一个视图导航到另一个视图。但在某些时候我想显示一个带有一些视图的UITabBarController。
(I select a user from a list and I want to show his profile (containing multiple views) with tabs)
(我从列表中选择一个用户,我想用选项卡显示他的个人资料(包含多个视图))
I searched, tried and nothing... I can't find someone that tried something like this.
我搜索过,尝试过,但一无所获……我找不到尝试过类似方法的人。
Can anyone give me some advice on how to create the nib file for UITabBarControllerand how to push it from a navigation controller?
谁能给我一些关于如何为UITabBarController创建 nib 文件以及如何从导航控制器推送它的建议?
回答by Rakesh Bhatt
Dont do that. add tabbatcontroller to ur mainwindow class. whenever you need tabar in app. just remove UINavigationController and add UITabBarController.
不要那样做。将 tabbatcontroller 添加到您的主窗口类。每当您需要在应用程序中使用 Tabar 时。只需删除 UINavigationController 并添加 UITabBarController。
or add add tabbatcontroller to ur mainwindow class and just present tababrcontroller from current viewcontroller.
或者将 tabbatcontroller 添加到你的主窗口类中,然后从当前的视图控制器中显示 tababrcontroller。
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
delegate.tCtr.selectedIndex = index;
delegate.tCtr.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:delegate.tCtr animated:YES];
回答by Mobile Developer iOS Android
Its an easy task, made a UIViewController and in that add as subview UITabBarController. Now you can simply push it using navigationcontroller to that controller.
它是一项简单的任务,制作了一个 UIViewController 并在其中添加为子视图 UITabBarController。现在您可以简单地使用导航控制器将其推送到该控制器。
MainScreen *mainScreen = [[MainScreen alloc] initWithNibName:@"MainScreen" bundle:nil];
mainScreen.navigationItem.hidesBackButton = YES;
self.navigationController.navigationBar.hidden = YES;
[self.navigationController pushViewController:mainScreen animated:YES];
And on MainScreen controller's viewDidLoad method add TabBarController as subview in self.view. Also made outlet of tabbarcontroller and conect it with interface builder TabBarController object.
并在 MainScreen 控制器的 viewDidLoad 方法上添加 TabBarController 作为 self.view 中的子视图。还制作了 tabbarcontroller 的出口,并将其与界面构建器 TabBarController 对象连接起来。
回答by Vijay-Apple-Dev.blogspot.com
Sure, why not just re-assign your new UIViewController's array to UITabBarController's viewControllers property? That will do the trick.
当然,为什么不将新的 UIViewController 数组重新分配给 UITabBarController 的 viewControllers 属性呢?这样就行了。
- (void)addNewControllers {
NSMutableArray *controllers = [NSMutableArray array];
UIViewController *c0 = [[[UIViewController alloc] init] autorelease];
[controllers addObject: c0];
UIViewController *c1 = [[[UIViewController alloc] init] autorelease];
[controllers addObject: c1];
UIViewController *c2 = [[[UIViewController alloc] init] autorelease];
[controllers addObject: c2];
[myTabBarController setViewControllers:controllers];
}
call above function
调用上面的函数
then [self.navcont pushviewcontroller:mytabbarcontroller animated:yes];
然后 [self.navcont pushviewcontroller:mytabbarcontroller 动画:yes];
here change those uiviewcontroller to ur own by replacing the nibname function with using IB
这里通过使用 IB 替换 nibname 函数将那些 uiviewcontroller 更改为您自己的
for more
更多
回答by Derreck Dean
Since @Rakesh Bhatt's answer worked for me, here's the equivalent Monotouch code to get it running. My situation was that I have a SignInViewController I show first, then replace it with a UITabBarController subclass.
由于@Rakesh Bhatt 的回答对我有用,这里有等效的 Monotouch 代码来让它运行。我的情况是我先展示了一个 SignInViewController,然后用 UITabBarController 子类替换它。
AppDelegate.Navigation.SelectedIndex = 0;
AppDelegate.Navigation.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
PresentViewController (AppDelegate.Navigation, true, null);