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?
You don't define what the button actually does. This is a line from my app:
cancelEdit:
, the selector, is in the current class (self) and is defined as:On this question:
I go the place where I need more information and press the escape (Esc) key. So, in this example:
...(beginning of line)... @selector(Place Cursor Here, press Esc) ...
A list of the available selectors will appear. For Microsoft programmers, this is like Intellisense, but you have to ask for it with Esc (it just doesn't appear automatically like in Visual Studio). Practically speaking, XCode does create most of whatever you're trying to create when you start typing and it really helps when you figure out the Tab key is your friend. (well... it's my friend... having the lonely life I have)
Now, if you need your own selector, you can place your label in there (mySelector: for example), then, further down in your code, build it:
- (IBAction)mySelector:(id)sender {
NSLog(@"You touched me THERE!");
}
Also, in the header (.h) file, be sure to put a corresponding:
-(IBAction) mySelector:(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.You might want that when creating lightweight UIViewController with bar and buttons, but do not want navigation overhead.