将按钮添加到导航工具栏

发布于 2024-10-18 05:47:14 字数 148 浏览 1 评论 0原文

如何将按钮添加到基于导航的应用程序中的导航工具栏?

rootController 默认是一个 tableView,这是完美的。我想向导航控制器添加一个“共享”按钮,以便我可以将其附加到我自己的方法中。

如果导航栏添加到代码中的某处,这是如何完成的?

How can a button be added to a navigation toolbar in an application which is navigation based?

The rootController is a tableView by default, and this is perfect. I would like to add a "share" button to the navigation controller so that I can attach it to my own method.

How is this done if the navigation bar is added in the code somewhere?

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

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

发布评论

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

评论(4

も星光 2024-10-25 05:47:14

要在代码中执行此操作,请转到您的视图 viewDidLoad 方法并创建一个 UIBarButtonItem

此代码将创建一个按钮,显示您想要的共享并将其放在右侧导航栏的。

- (void)viewDidLoad {
     [super viewDidLoad];
     UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithTitle:@"Share"     style:UIBarButtonItemStyleBordered target:self action:@selector(share)];

    self.navigationItem.rightBarButtonItem = shareButton;
    [shareButton release];
}

To do it in code, go to your views viewDidLoad method and create a UIBarButtonItem

This code will create a button that says share like you wanted and put it on the right hand side of the navigation bar.

- (void)viewDidLoad {
     [super viewDidLoad];
     UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithTitle:@"Share"     style:UIBarButtonItemStyleBordered target:self action:@selector(share)];

    self.navigationItem.rightBarButtonItem = shareButton;
    [shareButton release];
}
忆梦 2024-10-25 05:47:14
UIBarButtonItem *shareButton = [[[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStylePlain target:self action:@selector(yourShareAction)] autorelease];


self.navigationItem.rightBarButtonItem = shareButton;
UIBarButtonItem *shareButton = [[[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStylePlain target:self action:@selector(yourShareAction)] autorelease];


self.navigationItem.rightBarButtonItem = shareButton;
燃情 2024-10-25 05:47:14

这会创建一个添加按钮,但您明白了。

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
  initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
  target: 
  self action:@selector(buttonPressed:)] 
  autorelease];

This makes an add button, but you get the idea.

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
  initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
  target: 
  self action:@selector(buttonPressed:)] 
  autorelease];
情话难免假 2024-10-25 05:47:14

您可以创建一个 UIBarButtonItem 并将其附加到根视图控制器的导航项。在初始化 UIBarButtonItem 对象时添加目标操作对,并且当用户点击按钮时该操作消息将发送到目标。

因此,如果您希望在显示表视图时使用该按钮,请将 UIBarButtonItem 设置为表视图控制器的 navigationItem.rightBarButtomItem 属性。

You can create an UIBarButtonItem and attach it to a root view controller's navigation item. You add a target-action pair when you initialize the UIBarButtonItem object and that action message will be sent to the target on a user tapping on the button.

So if you want the button when the table view is shown, set the UIBarButtonItem to your table view controller's navigationItem.rightBarButtomItem property.

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