在TableView中选择每个Cell时呈现不同的视图

时间:2016-04-13 08:40:51

标签: ios xcode swift uitableview

我想在表格视图中选择每个单元格时提供不同的视图。

enter image description here

我发现我必须使用这个功能:

 func tableView(tableView: UITableView, didDeselectRowAtIndexPath   indexPath: NSIndexPath) {



}

我应该在函数内添加什么来使其工作?

2 个答案:

答案 0 :(得分:1)

首先,您需要didSelectRowAtIndexPath并且在函数内部可以使用indexPath.row来了解女巫单元格,然后您需要创建并推送您想要的视图

let viewControllerObj = self.storyboard?.instantiateViewControllerWithIdentifier("ViewControllerIdentifier") as? ViewController
self.navigationController?.pushViewController(viewControllerObj!, animated: true)

另外,请确保您的navigationController不是

...希望它有所帮助

答案 1 :(得分:0)

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
{

    if indexPath.row == 0
    {
        let objOne = self.storyboard?.instantiateViewControllerWithIdentifier("ID_OneScene") as? OneScene

        self.navigationController?.pushViewController(objOne!, animated: true)

    }
    else if indexPath.row == 1
    {
        let objTwo = self.storyboard?.instantiateViewControllerWithIdentifier("ID_TwoScene") as? TwoScene

        self.navigationController?.pushViewController(objTwo!, animated: true)

    }
    else
    {
        let objOther = self.storyboard?.instantiateViewControllerWithIdentifier("ID_OtherScene") as? OtherScene

        self.navigationController?.pushViewController(objOther!, animated: true)

    }

}