Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone navigation bar does not show all buttons on device

In Portrait mode on the iPhone Simulator or in Landscape on the Device, it shows all of the navigation bar buttons, but when used in Portrait mode on the Device, the button is not displayed. Below are images of the navigation bars.

Simulator shows button

Device doesn't show button

The device I have for testing is an iPhone 4S running iOS 6.1.3 (10B329). The simulator I am using is Version 7.0 (463.9.4) running iOS 6.0/6.1.

I am considering removing the Search button while in Edit mode, but I'd prefer to keep this option available to the user regardless of mode.

Any help or insight is appreciated, thanks.

Edit: The right buttons are initially created and added in viewDidLoad: for the ViewController like so:

_deleteBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteRows:)];
_deleteBarButtonItem.tintColor = [UIColor redColor];

_searchBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(searchButtonClicked:)];

self.navigationItem.rightBarButtonItems = @[_searchBarButtonItem, self.editButtonItem];

And when entering edit mode:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];

    if (self.tableView.isEditing) {
        // turn off editing
        _deleteBarButtonItem.enabled = NO;
        [self.tableView setEditing:NO animated:animated];
        [self.editButtonItem setStyle:UIBarButtonItemStylePlain];
        self.navigationItem.rightBarButtonItems = @[_searchBarButtonItem, self.editButtonItem];
    } else { 
        // turn on editing
        [self.tableView setEditing:YES animated:animated];
        [self.editButtonItem setStyle:UIBarButtonItemStyleDone];
        self.navigationItem.rightBarButtonItems = @[_searchBarButtonItem, _deleteBarButtonItem, self.editButtonItem];
    }
}
like image 286
DemonGyro Avatar asked Nov 11 '22 19:11

DemonGyro


1 Answers

Honestly, thats curious. Perhaps it is some property of the title that makes it dominant. In my experience, it is always best to have less options during "editing mode". If you decide to go that route, here is a little code that might help. (naturally, your variable names most likely differ)

// Get the reference to the current toolbar buttons
NSMutableArray *toolbarButtons = [self.toolbarItems mutableCopy];

if (editing) {
    // This is how you remove the button from the toolbar and animate it
    [toolbarButtons removeObject:self.myButton];
    [self setToolbarItems:toolbarButtons animated:YES];
} else {
    // This is how you add the button to the toolbar and animate it
    if (![toolbarButtons containsObject:self.myButton]) {
        // The following line adds the object to the end of the array.  
        // If you want to add the button somewhere else, use the `insertObject:atIndex:` 
        // method instead of the `addObject` method.
        [toolbarButtons addObject:self.myButton];
        [self setToolbarItems:toolbarButtons animated:YES];
    }
}
like image 125
William Riley Avatar answered Nov 15 '22 06:11

William Riley