two buttons on UINavigator
I would like to add 2 buttons to the UINavigator controller I tried to create a button first and then add i开发者_JS百科t to a UIToolbar but just can't get it to work.
Here's an image of what I want :)
link
Any help would be appreciated
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
addButton.frame = CGRectMake(40, 40, 44, 44);
[addButton setTitle:@"YES" forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
NSArray* buttons = [NSArray arrayWithObjects:self.editButtonItem, addButton, nil];
[toolbar setItems:buttons animated:NO];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
}
- (IBAction)buttonClicked:(id)sender
{
NSLog(@"Hi!");
}
You can just do:
self.navigationItem.rightBarButtonItem = toolbar;
精彩评论