【发布时间】:2016-05-28 10:26:54
【问题描述】:
我有一个主 TableViewController。当用户点击 TableView 中的单元格时,如果条件语句为真,则再次显示主 TableViewController(但在屏幕上显示另一个数据),如果条件为假,则显示另一个 ViewController。 在 prepareForSegue 方法中我有这个:
if segue.identifier == "identifier1"
{
let destination = segue.destinationViewController as? mainViewController // itself
destination!.x = something // the x variable is in this view controller
}
else if segue.identifier == "identifier2"
{
let destination = segue.destinationViewController as? viewController2
destination!.y = something
}
另外,为了在点击 tableView 中的单元格后运行 segue,我添加了这个:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
if condition is true {
self.performSegueWithIdentifier("identifier1", sender: self)
}
else{
self.performSegueWithIdentifier("identifier2", sender: self)
}
}
Storyboard segue 需要一个标识符...它只能有一个值!标识符 1 或标识符 2 但我想以编程方式设置标识符。 我应该如何在 Storyboard segue 中设置标识符? 还有另一种方法可以做到这一点吗? 谢谢!
【问题讨论】:
标签: ios swift uitableview segue