2017-03-09 56 views
1

我想導航到一個特定的viewController。我有兩個viewControllers相同的tableView插座一個是主要的VC和第二個是requestHistory VC。例如,如果用戶在第一個viewController上並選擇tableview中的單元格,它應該導航到特定的viewController,如果用戶在第二個VC上並且選擇了應該重定向到另一個VC的同一個單元,則它應該導航到第二個VC。請注意,我使用相同的表格視圖單元插座VC和所需的結果是每個VC故事板應重定向到他們的具體destination.i'm不知道我面臨的錯誤 這裏是我的代碼所以遠:XCode swift 3如果當前viewController在tableView中導航didSelect

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    print("Row \(indexPath.row) selected") 

    var currentStoryboard = UIStoryboard(name: "DoctorHomeViewController", bundle: nil) 

    if currentStoryboard == "DoctorHomeViewController" { 
    let storyboardd = UIStoryboard(name: "DoctorHome", bundle: Bundle.main) 
    let eventViewController = storyboardd.instantiateViewController(withIdentifier: "EventDetailsNav") as? UIViewController 
    self.navigationController?.pushViewController(eventViewController!, animated: true) 
    } 

    else{ 
     let storyboardd = UIStoryboard(name: "DoctorHome", bundle: Bundle.main) 
     let eventViewController = storyboardd.instantiateViewController(withIdentifier: "RequestsHistory") as? UIViewController 
     self.navigationController?.pushViewController(eventViewController!, animated: true) 
    } 
    } 
} 

任何幫助將是非常可觀的。

+0

問題不清楚..請詳細說明。 –

+0

請詳細說明你想要做什麼。 – PGDev

回答

0

首先,您需要在身份檢查器中爲故事板中的相應視圖控制器標記「使用故事板ID」,然後獲取故事板ID並將其與yourView控制器進行比較。

let currentStoryboard : String! = self.restorationIdentifier 
    if currentStoryboard == "DoctorHomeViewController" { 
     let storyboard = UIStoryboard(name: "DoctorHome", bundle: Bundle.main) 
     let eventViewController = storyboard.instantiateViewController(withIdentifier: "EventDetailsNav") as! EventDetailsNav 
     self.navigationController?.pushViewController(eventViewController!, animated: true) 
    } 

    else{ 
     let storyboard = UIStoryboard(name: "DoctorHome", bundle: Bundle.main) 
     let eventViewController = storyboard.instantiateViewController(withIdentifier: "RequestsHistory") as RequestsHistory 
     self.navigationController?.pushViewController(eventViewController!, animated: true) 
    } 

希望這會幫助你。

+0

它沒有與我一起工作,請參閱編輯文本 –

+0

你正在得到什麼錯誤? – Pankaj

相關問題