0
我有一個的tableView,並在我的indexpath.section 4,我有「我的帳戶」是挖掘時,它應該表現出兩種不同的觀點視情況而定,我想要做的是:如何使用單個表格部分顯示不同的視圖?
當用戶第一次涉及到應用程序的一部分,顯示登錄視圖控制器
如果用戶在顯示「帳戶視圖控制器」持有用戶信息,如果沒有則顯示常規的「登錄瀏覽器登錄「
一切都與導航控制器連接到視圖之間移動,因爲我使用的SWRevealVIewController使用側面菜單或抽屜菜單
這裏是代碼我想要使用
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.section)
let isUserLoggedIn = UserDefaults.standard.bool(forKey: "isUserLoggedIn")
if indexPath.section == 4 {
if isUserLoggedIn {
let AccountVC = self.storyboard?.instantiateViewController(withIdentifier: "AccountViewController") as! AccountViewController
self.present(AccountVC, animated: true, completion: nil)
}else{
let LoginVC = self.storyboard?.instantiateViewController(withIdentifier: "LoginView") as! LoginViewController
self.present(LoginVC, animated: true, completion: nil)
}
}
}
謝謝
主要問題是,一旦用戶登錄,「登錄視圖控制器」將不會執行「帳戶視圖控制器」的繼續 – SCS
據我所知,沒有涉及到因爲您手動實例化視圖控制器通過故事板並以編程方式呈現。如果你想使用segues,你應該調用「performSegue(withIdentifier)」,而不是實例化視圖控制器,並調用「present()」 – xxtesaxx
現在我得到它的工作,但「帳戶視圖」不會停留,這意味着如果用戶轉到表格視圖的另一部分並返回到「我的帳戶」,然後返回到「登錄視圖」 – SCS