导航栏中的多个栏按钮未在iOS 6上显示

时间:2012-12-21 07:11:57

标签: iphone ipad xcode4 uibarbuttonitem

我使用属性rightBarButtonItems为导航项添加了一个bar按钮数组,它适用于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。

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

1 个答案:

答案 0 :(得分:1)

如果要在NavigationBar的rightBarButtonItems上添加multiButton,请使用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];

enter image description here

然后在第一个按钮的另一侧添加第二个按钮。