More than 1 rightBarButtonItem on navigation bar

前端 未结 9 989
清歌不尽
清歌不尽 2021-01-30 02:06

I would like to have two rightBarButtonItems on navigation bar. One for Edit and the other for Add.

Obviously I can\'t make it using Interface Builder.

Does anyb

9条回答
  •  悲&欢浪女
    2021-01-30 02:24

    Here's the really easy, 2 line answer:

    Step 1: Create a nib for the custom view w/ whatever content you want

    Step 2: Add the nib to the toolbar as a custom view:

    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"TwoButtonView" owner:self options:nil];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[subviewArray objectAtIndex:0]];
    

提交回复
热议问题