多Barbutton在导航栏上没有显示iOS6的(Multiple Barbutton in Nav

2019-10-17 12:55发布

我已经加入栏按钮来使用属性rightBarButtonItems的导航项目的阵列,它的工作好了iOS5的,当我在iOS6的测试只有一个栏按钮项目可见。

UIBarButtonItem *updateButton          = [[UIBarButtonItem alloc]
                                          initWithTitle:@"Update"
                                          style:UIBarButtonItemStylePlain
                                          target:self
                                          action:@selector(updateData)];

UIBarButtonItem *refreshButton          = [[UIBarButtonItem alloc]
                                          initWithTitle:@"Refresh"
                                          style:UIBarButtonItemStylePlain
                                          target:self
                                          action:@selector(refresh)];

NSArray *arrBtns = [[NSArray alloc]initWithObjects:updateButton,refreshButton, nil];

self.navigationItem.rightBarButtonItems=arrBtns;

有没有什么新的属性iOS6的补充栏按钮的阵列navigationitem。

任何帮助,将不胜感激,非常感谢。

Answer 1:

如果你想在导航栏的rightBarButtonItems添加多按键,请在rightBarButtonItems使用segmentController

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
                                            [NSArray arrayWithObjects:@"Add",@"Delete",
                                             nil]];
    segmentedControl.frame = CGRectMake(0, 0, 80, 30);
    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    [segmentedControl setWidth:35.0 forSegmentAtIndex:0];
    [segmentedControl setWidth:45.0 forSegmentAtIndex:1];

    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    segmentedControl.momentary = YES;

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

    self.navigationItem.leftBarButtonItem = segmentBarItem;
    [segmentBarItem release];

其次加上第一栏按钮的另一侧的第二个按钮。



文章来源: Multiple Barbutton in Navigation Bar not showing on iOS6