[英]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.