开发者

Adding UIButton top bar of a navigation controller that pushes to another viewController

开发者 https://www.devze.com 2023-04-09 18:13 出处:网络
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.

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)];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号