Using a navigation bar to get something similar to the picker in the iPhone Safari app?
In Safari, when I press a dropdown box, a picker comes up with a navigation bar on top of it that h开发者_Python百科as a done button and some other buttons.
I want a similar bar with two buttons above my picker view, but I can't figure out how to put buttons on the bar. With a navigation controller, I'd do:
self.navigationItem.rightBarButtonItem = [UIButton .....
self.navigationItem.backBarButtonItem = [UIButton ......
But I'm not finding any button properties on the navigation bar that I'm creating programmatically. Adding the buttons as subviews also doesn't seem to be doing anything. How can I add them?
It’s a toolbar, not a navigation bar. Set its items
property to populate it with UIBarButtonItem objects. Note that those are not the same as UIButtons, and in fact don’t even subclass from UIView; they have their own set of attributes. A simple example:
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolbar.items = [NSArray arrayWithObjects:
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed)] autorelease],
nil];
someTextField.inputAccessoryView = toolbar;
[toolbar release];
精彩评论