alexey.stalker
alexey.stalker

Reputation: 63

Can't place two buttons in NavigationItem.RightBarButtonItems in MonoTouch

In my project, I need to add two UIBarButtonItems to a NavigationItem of a view controller. I solved this with this code:

UIBarButtonItem saveButton = new UIBarButtonItem("Save", UIBarButtonItemStyle.Bordered, (sender, e) => {
    //some saving code...
    });
    UIBarButtonItem delButton = new UIBarButtonItem("Delete", UIBarButtonItemStyle.Done, (sender, e) => {
    //some deletion code...
    });
    UIBarButtonItem[] items = new UIBarButtonItem[]
    {
        saveButton,
        delButton
    };
    this.NavigationItem.RightBarButtonItems = items;

It worked in previous versions of MonoTouch (on iOS 5, both device and simulator), but (I think so) after I upgraded to MonoTouch 6, only first button from the array is displayed. I try to use NavigationItem.SetRightBarButtonItems(items, false) method, but without any effect.

Is it a common problem or I am doing something wrong?

Upvotes: 2

Views: 1456

Answers (2)

alexey.stalker
alexey.stalker

Reputation: 63

OK, here is the case. The situation described in my question happens when you already have a back button and a some custom view (i.e. UISegmentedControl instance) in a navigationItem.TitleView. In this case, when you set navigationItem.RightBarButtonItems with an array of UIBarButtonItems and the space is not enough to display a navigationItem.TitleView and both right buttons, iOS renders only the first button of the array and discard the other. I verified this in a native ObjC application and got the same behavior.

Upvotes: 1

poupou
poupou

Reputation: 43543

Is it a common problem or I am doing something wrong?

Touch.Unit, MonoTouch's unit test runner, use RightBarButtonItems and works correctly (showing both buttons) with MonoTouch 6.0.x.

OTOH I see nothing wrong in your code snippet (but it's a short one). Your best bet is to create a small, self contained, application that shows your issue and attach it to a bug report. We'll be able to review it and see what's wrong (or you might find the issue yourself, if it's inside your own code, when doing the test case).

Upvotes: 1

Related Questions