UINavigationController和presentModalViewController [英] UINavigationController and presentModalViewController

查看:39
本文介绍了UINavigationController和presentModalViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结合了TabController和UINavigationController的应用程序.

I have a application combined with TabController and UINavigationController.

按下按钮时,我要弹出另一个带有其自己的UINavigationController的窗口.

When a button is pressed, I want to pop up another window with its own UINavigationController.

-(void) buttonPushed: (UIBarButtonItem *) myButton
{

    MyNavigationController *controller = [[MyNavigationController alloc] initWithNibName:@"MyNavigationController" bundle:nil];

    MyDelegate *appDelegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];    
    [appDelegate.rootController presentModalViewController:controller animated:YES];
}

窗口显示,但是我有一个完整的空白导航栏,但没有看到我在nib文件中对标题的修改.

The window shows, but I got an complete blank navigation bar and I don't see my modification of title in nib file.

我猜我设置笔尖时出了点问题,因为当我用一个基本的视图控制器替换导航控制器时,它加载正常.

I guess there is something wrong when I set the nib because when I replace the navigation controller with an basic view controller one, it loads OK.

那么你知道哪里出了什么问题吗?

So any idea what goest wrong?

推荐答案

您必须先将视图添加到NavController,然后在模式窗口中显示NavController.尝试这样的事情:

You have to add your view to the NavController first, and then display the NavController in the modal window. Try something like this:

MyController *controller = [[MyController alloc] initWithNibName:@"controllerNib" bundle:nil];

  //Place controller in navController
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:controller];

//Display in form sheet modal window
navController.modalPresentationStyle = UIModalPresentationFormSheet;

 MyDelegate *appDelegate = (MyAppDelegate*) [[UIApplication sharedApplication] delegate];    
[appDelegate.rootController presentModalViewController:navController animated:YES];

完成此操作后,您可以随时在控制器视图控制器中将新视图推送到navController上.它将自动处理后退按钮和所有爵士乐.就这么简单:)

Once you do that, you can push a new view onto the navController anytime you want inside the controller view controller. It will automatically handle the back buttons and all that jazz. Simple as that :)

这篇关于UINavigationController和presentModalViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆