在 UINavigationController 上添加按钮

发布于 2024-09-24 18:13:55 字数 244 浏览 6 评论 0原文

我正在尝试开发我的第一个 iPhone 应用程序。我使用具有三个视图的 navigationController:主视图 -> 第一个视图 -> 第二个视图。我想仅在第一个视图上添加一个按钮,我尝试如下:

self.navigationItem.rightBarButtonItem = self.editButtonItem;

但什么也没有出现。如果我在主视图上添加按钮,它会出现在每个视图上,可以执行我想要的操作吗? 谢谢!

i'm trying to develop my first iphone apps. I'm using a navigationController with three views: main->first view ->second view. I would like to add a button only on the first view, i tried like this:

self.navigationItem.rightBarButtonItem = self.editButtonItem;

but nothing appear. If I add the button on the main view it appears after on each view, is possible to do what I want?
Thanks!

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

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

发布评论

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

评论(3

我们只是彼此的过ke 2024-10-01 18:13:55

要添加到其他人指出的答案的另一点是,要在工具栏上添加按钮,请确保您正在访问添加到 UINavigationController 的视图控制器。您应该像这样修改视图控制器。

navController=[[UINavigationController alloc] initWithRootViewController:viewController];
[viewController.navigationItem  setRightBarButtonItem:rightBarButton];

One more point to add to the answers pointed out by others is that for adding a button on the toolbar please ensure that you are accessing your view controller which is added to the UINavigationController.You should be modifying the view controller like this..

navController=[[UINavigationController alloc] initWithRootViewController:viewController];
[viewController.navigationItem  setRightBarButtonItem:rightBarButton];
软的没边 2024-10-01 18:13:55
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"YOUR TITLE" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"YOUR TITLE" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
奢欲 2024-10-01 18:13:55
UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"buttonImage.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 49, 30)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"buttonImage.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 49, 30)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文