添加导航控制器的 UIButton 顶栏,推送到另一个 viewController
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您初始化 UIBarButtonItem 时,您是否看到一个名为 action: 的参数?在那里提及一个选择器:
上面的项目应该是您想要的 rightBarButton。
这将是你的选择器:
When you init your UIBarButtonItem, do you see a parameter called action: ? Mention a selector there:
The above item should be your rightBarButton as you want it to be.
And this would be your selector:
UIBarButtonItem addButton=[[UIBarButtonItem alloc]initWithTitle:@"+" style:UIBarButtonItemStyleBordered target:self action:@selector(method)];
UIBarButtonItem addButton=[[UIBarButtonItem alloc]initWithTitle:@"+" style:UIBarButtonItemStyleBordered target:self action:@selector(method)];