2017-12-18 49 views
0

내비게이션 컨트롤러가없는 ViewController에서 ViewController으로 이동 중입니다.내비게이션 컨트롤러에 버튼 추가

프로그래밍 방식으로 NavigationController을 만들었지 만 탐색 모음에 버튼을 추가하는 데 어려움이 있습니다. LocationTableViewController.swift

// MARK: - View Will Appear 
override public func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(animated) 
    UIApplication.shared.statusBarStyle = .lightContent 

    // Make Nav Bar Translucent and Set title font/color 
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) 
    self.navigationController?.navigationBar.shadowImage = UIImage() 
    self.navigationController?.navigationBar.isTranslucent = true 
    self.navigationController?.view.backgroundColor = .clear 
    self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: .semibold)] 
    self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back-arrow-white") 

} 
+1

어떤 단추를 추가 하시겠습니까? –

+0

커스텀 뒤로 버튼 – pmanning

+0

'self.navigationItem.leftBarButtonItem = UIBarButtonItem (.....)'또는'self.navigationItem.backBarButtonItem = UIBarButtonItem (....)'주의 :'viewWillAppear '.. 그것은'viewDidLoad'에서 할 수 있습니다. 'navigationBar' 속성에만 액세스하려면'viewWillAppear' 또는 생성자가 필요합니다. 모든 뒤로 버튼을 대신 사용자 정의 이미지로 사용하려면'UIAppearance' 프록시를 사용하십시오. – Brandon

답변

0

func goToLocation() { 
    let locationTableVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "locationProfile") as! LocationTableViewController 
    locationTableVC.documentId = selectedDocumentId! 

    let navigationController = UINavigationController(rootViewController: locationTableVC) 

    self.present(navigationController, animated: true, completion: nil) 
} 

는 &이 navigationItem의 leftBarButtonItem로 설정 UIBarButtonItem 사용하여 사용자 정의보기를 만듭니다.

override func viewDidLoad() { 

    super.viewDidLoad() 
    let backButton = UIButton(type: .custom) 
    backButton.frame = CGRect(x:0,y:0,width: 45, height:45) 
    backButton.setImage(UIImage(named: "back-arrow-white"), for: .normal) 
    let backBarButtonItem = UIBarButtonItem.init(customView: backButton) 
    self.navigationItem.leftBarButtonItem = backBarButtonItem; 

}