导航工具栏右侧两个按钮

发布于 2024-07-29 06:50:42 字数 196 浏览 2 评论 0原文

有谁知道如何在导航工具栏的右上角添加两个系统按钮? 我知道可以添加自定义按钮,但我真的不明白为什么系统按钮也不能这样做。

我真的需要它。 我需要一个添加按钮和一个编辑按钮。

编辑以重新排序和删除表行。 添加以添加新行。

我无法使用底部工具栏,因为那里有一个选项卡栏。

有人可以帮我吗?

Does anyone know how to add two system buttons to the top right side of my navigation toolbar? I know that custom buttons can be added, and I really don't understand why the system buttons can't do this too.

And I really need it. I need an add button and an edit button.

Edit to reorder and delete table rows.
Add to add a new row.

I can't use the bottom toolbar because I have a tabbar there.

Could somebody help me out?

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

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

发布评论

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

评论(3

活泼老夫 2024-08-05 06:50:42

像这样的东西应该可以工作(替换你自己的图像和动作方法):

#define ACTIONEDIT  0
#define ACTIONADD   1
...
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] 
       initWithItems: [NSArray arrayWithObjects: 
         [UIImage imageNamed:@"icon-edit.png"], 
         [UIImage imageNamed:@"icon-add.png"],
         nil]
       ];
[segmentedControl addTarget:self 
                     action:@selector(segmentAction:) 
           forControlEvents:UIControlEventValueChanged];

segmentedControl.frame = CGRectMake(0, 0, 90, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
[segmentedControl setEnabled:YES forSegmentAtIndex:ACTIONEDIT];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
                       initWithCustomView:segmentedControl];

...

- (void)segmentAction:(id)sender
{
  UISegmentedControl* segCtl = sender;
  int action = [segCtl selectedSegmentIndex];
  switch (action) {
    case ACTIONADD:
     [self addToList];
     break;
    case ACTIONEDIT:
     [self editList];
     break;
  }
} 

Something like this should work (substitute your own images and action methods):

#define ACTIONEDIT  0
#define ACTIONADD   1
...
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] 
       initWithItems: [NSArray arrayWithObjects: 
         [UIImage imageNamed:@"icon-edit.png"], 
         [UIImage imageNamed:@"icon-add.png"],
         nil]
       ];
[segmentedControl addTarget:self 
                     action:@selector(segmentAction:) 
           forControlEvents:UIControlEventValueChanged];

segmentedControl.frame = CGRectMake(0, 0, 90, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
[segmentedControl setEnabled:YES forSegmentAtIndex:ACTIONEDIT];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
                       initWithCustomView:segmentedControl];

...

- (void)segmentAction:(id)sender
{
  UISegmentedControl* segCtl = sender;
  int action = [segCtl selectedSegmentIndex];
  switch (action) {
    case ACTIONADD:
     [self addToList];
     break;
    case ACTIONEDIT:
     [self editList];
     break;
  }
} 
失与倦" 2024-08-05 06:50:42

使用默认的导航栏,你只能有三个按钮,除非我遗漏了一些东西。 左边一张,中间一张,右边一张。 即使您创建了一个较小的按钮并认为您有足够的空间,触摸也会全部注册到同一个按钮(无论链接到右侧还是左侧)。 如果您想获得像谷歌导航栏这样的功能,我建议您自己实现。 这真的不会那么困难,而且您将获得您想要的功能。 如果您决定这样做,我相信 SO 可以指导您完成困难的部分。

With the default navigation bar, you can only have three buttons, unless I'm missing something. One on the left, one in the center, and one on the right. Even if you create a smaller button and think you have enough space, the touches will all register to the same button (whichever is linked to the right or left). If you want to get functionality like google's navbars, I would suggest implementing it yourself. It really wouldn't be that difficult, and you would get exactly the functionality that you want. If you decide to do this, I'm sure SO can guide you through difficult parts.

琴流音 2024-08-05 06:50:42

我想知道如果您为 UINavigationItem 使用自定义视图会发生什么:

myViewController.navigationItem.titleView = myCustomView;

我想如果您那里没有按钮,则 titleView 可能会一直向右扩展。 我注意到,如果没有右键,标题文本会获得更多空间。

然后,您可以向该自定义视图添加一个标签(用于标题)和两个按钮。

I wonder what would happen if you'd use a custom view for your UINavigationItem:

myViewController.navigationItem.titleView = myCustomView;

I imagine the titleView might expand all the way to the right if you don't have a button there. I'noticed that title text gets more space if there is no right button.

Then you could add a label (for the title) and your two buttons to that custom view.

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