1

我已经创建了一个工具栏按钮并给出了 action() 来导航到其他 ViewController。但是代码不适用于 Navigation。并且无法为按钮分配图像。我该如何解决这个问题?

- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setToolbarHidden:NO];
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, 418, 320, 44);
[self.view addSubview:toolbar];
[toolbar release];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"update"  style:UIBarButtonItemStyleBordered  target:self action:@selector(updateAddress:)];    
NSMutableArray *toolbarItems = [NSMutableArray arrayWithObjects:customItem,  nil];    
[toolbar setItems:toolbarItems animated:NO];
}    

-(void)updateAddress{
DisplayMapViewController *updateView=[[DisplayMapViewController alloc]init];
UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:updateView];
[self.navigationController popToViewController:navi animated:YES];
}
4

1 回答 1

1

首先你应该正确设置选择器,你应该:从选择器中取出,因为你没有updateAddress方法的参数

应该是这样的

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"update"  style:UIBarButtonItemStyleBordered  target:self action:@selector(updateAddress)]; 

然后你需要DisplayMapViewController用它的 NibName初始化

DisplayMapViewController *updateView=[[DisplayMapViewController alloc]initWithNibName:@"DisplayMapViewController" bundle:nil];

然后只是弹出到你想要的视图。

[self.navigationController popToViewController:updateView animated:YES];

如果你已经有 rootViewController 那么你可以popToRootViewController

于 2013-03-12T12:18:27.467 回答