向导航栏添加按钮

发布于 2024-08-14 20:20:35 字数 172 浏览 2 评论 0原文

是否可以使用iPhone SDK向导航栏添加按钮?

我的导航栏中已经有 2 个按钮,分别为 leftBarButton 和 rightBarButton。我还需要 2 个按钮。如何实施?

我不需要将它们包含在导航栏本身中,这并不是强制性的。但由于该应用程序只包含一个表,我认为它不能在其他地方给出。

Is it possible to add buttons to the navigation bar using the IPhone SDK?

I already have 2 buttons in the navigation bar as leftBarButton and rightBarButton. I need 2 more buttons. How to implement that?

Its not obligatory that i need them to be included in the navigation bar itself. But since the application contains only a table, i don't think it can be given elsewhere.

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

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

发布评论

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

评论(1

落花浅忆 2024-08-21 20:20:35

您可以使用 UISegmentedControl。检查 UICatalog代码示例以检查其在导航栏中的用法。

这是一些示例代码:

       - (void)viewDidLoad {
[super viewDidLoad];

 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
                          [NSArray arrayWithObjects:
                           [UIImage imageNamed:@"up.png"],
                           [UIImage imageNamed:@"down.png"],
                           nil]];
      [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
      segmentedControl.frame = CGRectMake(0, 0, 90, 35);
      segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
      segmentedControl.momentary = YES;

      UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
        [segmentedControl release];

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

    - (void)segmentAction:(id)sender{

      if([sender selectedSegmentIndex] == 0){
       //do something with segment 1
       NSLog(@"Segment 1 preesed");
      }else{
       //do something with segment 2
       NSLog(@"Segment 2 preesed");
      }
    }

You can use the UISegmentedControl. Check the UICatalog code sample to check its usage in the navigation bar.

Here is some sample code:

       - (void)viewDidLoad {
[super viewDidLoad];

 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
                          [NSArray arrayWithObjects:
                           [UIImage imageNamed:@"up.png"],
                           [UIImage imageNamed:@"down.png"],
                           nil]];
      [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
      segmentedControl.frame = CGRectMake(0, 0, 90, 35);
      segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
      segmentedControl.momentary = YES;

      UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
        [segmentedControl release];

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

    - (void)segmentAction:(id)sender{

      if([sender selectedSegmentIndex] == 0){
       //do something with segment 1
       NSLog(@"Segment 1 preesed");
      }else{
       //do something with segment 2
       NSLog(@"Segment 2 preesed");
      }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文