这是我的代码。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.row == 0{
        self.navigationController?.pushViewController(self.storyboard?.instantiateViewControllerWithIdentifier("History") as! History, animated: true)
        TV.deselectRowAtIndexPath(indexPath, animated: false)
    }
}

我推送到另一个ViewController(名为History),我想将此ViewController中的值传递给History ViewController。

我知道我们可以使用segue和segue的destinationViewController和sourceViewController传递值。

但是在这种情况下,没有安全问题。

因此,我不知道如何将var的值分配给History的var。

有人可以帮助我吗?

最佳答案

let history = self.storyboard?.instantiateViewControllerWithIdentifier("History") as! History

//这里您可以访问历史记录的变量
history.yourVar=Assign Value

self.navigationController?.pushViewController(history, animated: true)

TV.deselectRowAtIndexPath(indexPath, animated: false)

关于ios - 如何通过插入NavigationStack将值传递给另一个ViewController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31690757/

10-13 04:29