2017-04-27 86 views
0

我是Xcode的初學者。最近我正在開發一個Objective_C項目。如何從後臺隱藏導航欄標題「BACK」

我懷疑是如何隱藏後退按鈕導航欄標題「BACK」(但需要出示後退按鈕箭頭。)

謝謝。

+0

嘗試這樣self.navigationItem.backBarButtonItem = [[的UIBarButtonItem頁頭] initWithTitle:@ 「」 樣式:UIBarButtonItemStylePlain目標:無行動:無]; –

+0

'UINavigationController'已經爲你自動完成了。你只需要改變** previous **視圖控制器的'title'屬性。假設你有'vcA'和'vcB'視圖控制器,並且你從'vcA'推到'vcB'。帶有後退按鈕的'UINavigationBarItem'將在'vcB'中從'vcA'中取得標題並顯示出來。因此,如果您在推送前將空字符串設置爲'vcA'的標題,'vcB'中的後退按鈕也會顯示空字符串。 –

回答

0

使用此:

YourViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"YourViewController"]; 
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; 
[self.navigationController pushViewController:viewController animated:YES]; 
+0

先生。運行時返回錯誤UIApplicationMain(argc,argv,nil,NSStringFromClass([AppDelegate class])); –

0

我建議你使用代碼象下面這樣:

- (void)configureNavigationBarButtonItem 
{ 

UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom]; 
[cancel setFrame:CGRectMake(0, 0, 50, 50)]; 

[cancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
[cancel.titleLabel setFont:[UIFont fontWithName:@"Verdana" size:13.0f]]; 
cancel.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft; 
[cancel addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside]; 
cancel.tag=3200; 

imgBack = [[UIImageView alloc]initWithFrame:CGRectMake(5, 15, 18, 18)]; 
imgBack.image = [UIImage imageNamed:@"back_black"]; 
[cancel addSubview:imgBack]; 


UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithCustomView:cancel]; 
self.navigationItem.leftBarButtonItem = cancelBtn; 

} 
- (void)goBack:(id)sender 
{ 
    [self.navigationController popViewControllerAnimated:YES]; 
}