Adding UIButton top bar of a navigation controller that pushes to another viewController
I have a UIButton
that pushes to another view controller using the following code. How do I go about putting this UIButton
to the top bar of a navigation controller.
-(IBAction) nextButtonPressed {
TipsViewController *objYourViewController = [[TipsViewController alloc] initWithNibName:@"TipsViewController" bundle:nil];
[self.navigationController pushViewController:objYourViewController animated:YES];
[TipsViewController release];
}
I was thinking of adding something like: self.navigationItem.rightBarButtonItem
somewhere, but can't figure out the syntax.
Here's something else I tried with the following code: I can get a "Next" button in the top bar of the Navigation Controller. How would I get it to push to another view controller?
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self pushViewController:anotherButton animated:YES];
self.navigati开发者_JS百科onItem.rightBarButtonItem = anotherButton;
[anotherButton release];
thanks for any help.
When you init your UIBarButtonItem, do you see a parameter called action: ? Mention a selector there:
UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(Next:)];
The above item should be your rightBarButton as you want it to be.
And this would be your selector:
-(void)Next:(id)sender {
[self.navigationController pushViewController:nextViewController animated:YES];
}
UIBarButtonItem addButton=[[UIBarButtonItem alloc]initWithTitle:@"+" style:UIBarButtonItemStyleBordered target:self action:@selector(method)];
精彩评论