目前正在快速开发一个小型 ios 应用程序,我已经使用 .plist 中的数据填充了一个 Collection View 单元格,每个单元格都有一个标题和按钮,我想要的是根据 Storyboard 中的多个 View Controller 按下按钮后在 segue 标识上。例如,如果 segue 将 id 设置为食物,我希望它导航到名为食物的 View ?
或者如果 segue 更容易从单元格中提取标题然后导航到与单元格具有相同标题的 View ?
我会尝试用代码来解释:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
if segue.identifier == "food"
{
//then navigate to the view controller called food
}
else if segue.identifier == "drink"{
{
//navigate to the view called drink
}
}
最佳答案
如果食物、饮料或任何其他元素在 Storyboard中有其独特的视角,这是可以实现的。
您可以为 UICollectionView 中的每个按钮分配一个字符串,并检查集合中的哪个项目被点击,然后使用按钮字符串执行 performSegueWithIdentifier:
。
performSegueWithIdentifier("toComments", sender: self)
然后prepareForSegue:
方法传递数据。做另一个如果喝。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "toFood" {
let ExchangeViewData = segue.destinationViewController as! FoodViewController
ExchangeViewData.foodMenuToShow = foodMenuID //This can be anything that you get your food items.
}
}
关于ios - 如何根据 Segue 身份从 Collection View 单元格转到特定的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34004252/