Multiple Barbutton in Navigation Bar not showing on iOS6

为君一笑 提交于 2019-12-11 12:11:22

问题


I have added array of bar button to the navigation items using the property rightBarButtonItems,it work good for iOS5,when i tested in iOS6 only one bar button item is visible.

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;

Is there any new property for iOS6 to add the array of bar button to navigationitem.

Any help would be appreciated,Thanks a lot.


回答1:


Please use the segmentController on the rightBarButtonItems if you want to add multiButton on rightBarButtonItems of NavigationBar

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];

Secondly add the second button on other side of the first bar Button.



来源:https://stackoverflow.com/questions/13985839/multiple-barbutton-in-navigation-bar-not-showing-on-ios6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!