初始化新的导航控制器时如何将栏按钮项目添加到根视图控制器
当我初始化导航控制器时,我想将右栏按钮项目添加到根视图控制器的导航栏。因此自定义视图控制器不在导航控制器中,下一个将是。 我的代码是:
TipsViewController *tipsView = [[TipsViewController alloc] initWithNibName:@"TipsViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tipsView];
self.loginViewDelegate = tipsView;
UINavigationItem *navigationItem = [[navigationController navigationItem] init];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"load" style:UIBarButtonItemStylePlain target:self action:nil];
navigationItem.rightBarButtonItem = barButtonItem;
[self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[loginViewDelegate passRegistrationResult:str];
[self presentModalViewController:navigationController animated:YES];
[tipsView release];
[navigationController release];
我尝试这个但不起作用......
I want to add an rightbarbuttonitem to a root view controller's navbar when I init a navigationcontroller.So custom view controller is not in navigationcontroller, next will be.
my code is:
TipsViewController *tipsView = [[TipsViewController alloc] initWithNibName:@"TipsViewController" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tipsView];
self.loginViewDelegate = tipsView;
UINavigationItem *navigationItem = [[navigationController navigationItem] init];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"load" style:UIBarButtonItemStylePlain target:self action:nil];
navigationItem.rightBarButtonItem = barButtonItem;
[self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[loginViewDelegate passRegistrationResult:str];
[self presentModalViewController:navigationController animated:YES];
[tipsView release];
[navigationController release];
I try this but not work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
api PresentModalViewController:animated:
它的第一个参数是 UIViewController,UINavigationController 是 UIViewController 的子类。
因此,不能直接呈现 UINavigationController,但您可以呈现 UIViewController 并手动向其添加 UINavigationBar 和 UIBarbuttonItem 或使用 Interface Builder。
尽管我不太确定,但希望它可以帮助你〜:)
The api presentModalViewController:animated:
Its first param is UIViewController and UINavigationController is UIViewController's subclass.
So,cannot directly present a UINavigationController but you can present a UIViewController and add UINavigationBar and UIBarbuttonItem to it manually or use Interface Builder.
Hopes it can help you despite I'm not very sure ~ :)