2013-03-12 98 views
1

我已經創建了一個工具欄按鈕,並給出action()以導航到其他ViewController.But代碼不適用於Navigation.And不能將圖像分配給button.How can解決這個?如何使用工具欄按鈕創建導航

- (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

首先,你應該設置的選擇權,則應該從選擇取出:,因爲你沒有參數爲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