添加导航控制器的 UIButton 顶栏,推送到另一个 viewController

发布于 2024-12-07 04:48:12 字数 859 浏览 0 评论 0原文

我有一个 UIButton,它使用以下代码推送到另一个视图控制器。我该如何将此 UIButton 放置到导航控制器的顶部栏。

-(IBAction) nextButtonPressed {     
    TipsViewController *objYourViewController = [[TipsViewController alloc] initWithNibName:@"TipsViewController" bundle:nil];
    [self.navigationController pushViewController:objYourViewController animated:YES];
    [TipsViewController release];
}

我正在考虑在某处添加类似以下内容的内容: self.navigationItem.rightBarButtonItem ,但无法弄清楚语法。

这是我使用以下代码尝试的其他内容:我可以在导航控制器的顶部栏中找到“下一步”按钮。我如何将其推送到另一个视图控制器?

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self pushViewController:anotherButton animated:YES];          
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];

感谢您的帮助。

I have a UIButton that pushes to another view controller using the following code. How do I go about putting this UIButton to the top bar of a navigation controller.

-(IBAction) nextButtonPressed {     
    TipsViewController *objYourViewController = [[TipsViewController alloc] initWithNibName:@"TipsViewController" bundle:nil];
    [self.navigationController pushViewController:objYourViewController animated:YES];
    [TipsViewController release];
}

I was thinking of adding something like: self.navigationItem.rightBarButtonItem somewhere, but can't figure out the syntax.

Here's something else I tried with the following code: I can get a "Next" button in the top bar of the Navigation Controller. How would I get it to push to another view controller?

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self pushViewController:anotherButton animated:YES];          
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];

thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

作死小能手 2024-12-14 04:48:12

当您初始化 UIBarButtonItem 时,您是否看到一个名为 action: 的参数?在那里提及一个选择器:

UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(Next:)];

上面的项目应该是您想要的 rightBarButton。

这将是你的选择器:

-(void)Next:(id)sender {
    [self.navigationController pushViewController:nextViewController animated:YES];
}

When you init your UIBarButtonItem, do you see a parameter called action: ? Mention a selector there:

UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(Next:)];

The above item should be your rightBarButton as you want it to be.

And this would be your selector:

-(void)Next:(id)sender {
    [self.navigationController pushViewController:nextViewController animated:YES];
}
多情出卖 2024-12-14 04:48:12

UIBarButtonItem addButton=[[UIBarButtonItem alloc]initWithTitle:@"+" style:UIBarButtonItemStyleBordered target:self action:@selector(method)];

UIBarButtonItem addButton=[[UIBarButtonItem alloc]initWithTitle:@"+" style:UIBarButtonItemStyleBordered target:self action:@selector(method)];

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