2017-04-14 90 views
2

我是iOS開發新手。我想用Firebase構建授權。我正在使用FirebaseUI-iOS。我想隱藏取消按鈕從初始屏幕。你有什麼想法如何做到這一點?FirebaseUI iOS刪除取消按鈕

創建火力地堡authViewController編程:

import UIKit 
import Firebase 
import FirebaseAuthUI 
import FirebaseGoogleAuthUI 

class AuthViewController: UIViewController { 

fileprivate var _authHandle: FIRAuthStateDidChangeListenerHandle! 
var user: FIRUser? 

override func viewDidLoad() { 
    super.viewDidLoad() 
    configureAuth() 
} 

func configureAuth() { 
    let provider: [FUIAuthProvider] = [FUIGoogleAuth()] 
    FUIAuth.defaultAuthUI()?.providers = provider 
    FUIAuth.defaultAuthUI()?.isSignInWithEmailHidden = true 

    // listen for changes in the authorization state 
    _authHandle = FIRAuth.auth()?.addStateDidChangeListener { (auth: FIRAuth, user: FIRUser?) in 
     // check if there is a current user 
     if let activeUser = user { 
      // check if the current app user is the current FIRUser 
      if self.user != activeUser { 
       self.user = activeUser 
       let name = user!.email!.components(separatedBy: "@")[0] 
       print(name) 
      } 
     } else { 
      // user must sign in 
      self.loginSession() 
     } 
    } 
} 

func loginSession() { 
    let authViewController = FUIAuth.defaultAuthUI()!.authViewController() 
    present(authViewController, animated: true, completion: nil) 
} 

deinit { 
    FIRAuth.auth()?.removeStateDidChangeListener(_authHandle) 
} 
} 

enter image description here

+0

除了從下面給出的答案,我想你可以在故事板做到這一點。只需搜索navigationItemLeft或其他東西。 –

+0

刪除指定一個左欄按鈕項目的代碼段,或者將其設置爲零。 –

+0

@TylerRutt我以編程方式使用此取消按鈕創建視圖控制器。我使用FirebaseUI-iOS。在這種情況下,我不確定必須移除按鈕。我用代碼更新了我的問題。有任何想法嗎? –

回答

3

對於您可以設置leftBarButtonItemnilviewDidLoadviewWillAppear

self.navigationItem.leftBarButtonItem = nil 
+0

問題是我以編程方式創建FirebaseUI authViewController。我不知道如何訪問它的viewDidLoad或viewWillAppear方法。我用當前的代碼更新了我的問題。 –

+0

@VitaliiIvanov你有沒有嘗試在'AuthViewController'的viewDidLoad中設置它? –

+0

是的,我試過了。它沒有幫助。我只知道如何隱藏整個導航欄。在loginSession函數中,我可以添加authViewController.navigationBar.isHidden = true。但我只需要隱藏取消按鈕。 –

3

延長VC,並將其添加在viewWillAppear中

extension FUIAuthBaseViewController{ 
    open override func viewWillAppear(_ animated: Bool) { 
    self.navigationItem.leftBarButtonItem = nil 
    } 
}