导航控制器后退按钮

时间:2011-11-18 08:49:42

标签: ios ipad xcode4 uinavigationcontroller

如何以编程方式创建导航控制器的后退按钮?

1 个答案:

答案 0 :(得分:25)

-(void)loadView或类似内容中:

UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(backPressed:)];
self.navigationItem.leftBarButtonItem = btn;
[btn release];

-(void)backPressed: (id)sender
{
    [self.navigationController popViewControllerAnimated: YES]; // or popToRoot... if required.
}