如何使用ToolBar按钮创建导航

时间:2013-03-12 12:13:10

标签: ios uinavigationcontroller uitoolbar

我创建了一个工具栏按钮并给出了action()以导航到其他ViewController.But代码不适用于Navigation.And无法将图像分配给按钮。我该如何解决这个问题?

- (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];
}

1 个答案:

答案 0 :(得分:1)

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

应该是这样的

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

然后您需要使用其NibName

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

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

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

如果您已经有rootViewController,那么您可以popToRootViewController