簡體   English   中英

動態TableView單元格到多個詳細信息視圖Swift

[英]Dynamic TableView Cell to Multiple Detail Views Swift

我正在使用presentViewController在XCode中的兩個視圖之間導航。 我想知道如何從動態tableView中選擇一個單元格行以導航到視圖控制器。 因此,基本上,當我點擊動態單元格時,每個單元格都導航到其自己的不同視圖。 我該怎么辦? 到目前為止,我有以下代碼:

@IBAction func press(sender: AnyObject) {

    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

    let vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("newViewController") as! UINavigationController

    self.presentViewController(vc, animated: true, completion: nil)

}

但是,如上所述,我希望不使用按鈕,而是希望每個單元格都導致另一個特定的視圖。

提前致謝

創建一個包含視圖控制器標識符的數組:

let identifiers = ["newViewController", "newViewController2", "newViewController3"]

在視圖控制器中實現此UITableViewDelegate方法:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if let identifier = identifiers[indexPath.row] {
        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("newViewController") as! UINavigationController
        self.presentViewController(vc, animated: true, completion: nil)
    }
}

不要忘記將tableView的委托設置為包含tableview並實現上述委托方法的視圖控制器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM