2017-08-31 73 views
0

顯示的UIViewController模態從視圖控制器(這是一個導航控制器) 碼之一:後退按鈕自定義導航項目不可見加入的UIViewController

self.present(viewController, animated: true, completion: nil) 

在模態視圖控制器,自定義導航酒吧與導航項目一起添加。其中,我試圖顯示後退按鈕。

let backButton = UIBarButtonItem() 
backButton.title = "Back" 
self.navigItem.backBarButtonItem = backButton //self.navigItem is the custom Navigation Item 

有什麼我在這裏失蹤?

在此先感謝, 拉傑什

+1

目前VC這個代碼不Navigationcontroller嵌入,如果你需要嵌入您的VC在導航控制器並呈現你的VC,否則在程序VC中以編程方式創建導航欄 –

+0

VC需要在導航控制器中未添加模塊地呈現, 已添加cu在StoryBoard中爲這個viewcontroller命令導航欄。我能夠添加/顯示除後退按鈕之外的其他酒吧按鈕項目。 –

+0

看到這個例子https://stackoverflow.com/questions/21448766/adding-navigation-bar-programmatically-ios/21448861#21448861 –

回答

0
let btnleft : UIButton = UIButton(frame: CGRect(x:0, y:0, width:35, 
          height:35)) 
btnleft.contentMode = .center 
btnleft.setImage(Set_Local_Image("arrow_left"), for: .normal) 
btnleft.addTarget(self, action: #selector(YOUR_ACTION), for: .touchDown) 

let backBarButon: UIBarButtonItem = UIBarButtonItem(customView: btnleft) 
self.navigationItem.setLeftBarButtonItems([menuBarButon], animated:false) 
0

在Swift3嘗試在viewDidLoad中

self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "arrow_left") 
    self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "arrow_left") 
    UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for:UIBarMetrics.default) 
    self.navigationController?.navigationBar.tintColor = UIColor.white 
    self.navigationItem.hidesBackButton = false 
相關問題