初始化新的导航控制器时如何将栏按钮项目添加到根视图控制器

发布于 2024-12-10 19:15:35 字数 1000 浏览 0 评论 0原文

当我初始化导航控制器时,我想将右栏按钮项目添加到根视图控制器的导航栏。因此自定义视图控制器不在导航控制器中,下一个将是。 我的代码是:

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素罗衫 2024-12-17 19:15:35

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 ~ :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文