I've created a new navigation based iPhone app. I added this to the RootViewController.
- (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem *addButton = [[UIBarButtonItem alloc] init]; self.navigationItem.leftBarButtonItem = addButton; self.navigationItem.leftBarButtonItem.enabled = YES; }
No left button displays however. Is there something I need to do?
Example ExplainedUse any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.
You don't define what the button actually does. This is a line from my app:
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelEdit:)];
cancelEdit:
, the selector, is in the current class (self) and is defined as:
- (void) cancelEdit: (id) sender;
There is actually another answer, which is not listed here, but might be very useful in many cases. If you do not want to use UINavigationController, then self.navigationItem
is not an option for you.
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"imageName"] style:UIBarButtonItemStyleBordered target:self action:@selector(action:)]; UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Bar Title"]; navigationItem.leftBarButtonItem = barButton; [navigationBar pushNavigationItem:navigationItem animated:NO];
You might want that when creating lightweight UIViewController with bar and buttons, but do not want navigation overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With