加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

通过单击表视图中的单元格 – Swift iOS打开新的视图控制器

发布时间:2020-12-14 05:55:57 所属栏目:百科 来源:网络整理
导读:我有以下onClick函数 func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath) { tableView.deselectRowAtIndexPath(indexPath,animated: true) let row = indexPath.row println("Row: (row)") println(meetingArray[row]
我有以下onClick函数
func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath) {

    tableView.deselectRowAtIndexPath(indexPath,animated: true)

    let row = indexPath.row
    println("Row: (row)")

    println(meetingArray[row] as! String)

}

它打印出单击的单元格上的文本。工作正常

我只是想知道如何设置一个功能,这将引导您到新的视图控制器

编程方式:
let destination = UIViewController() // Your destination
navigationController?.pushViewController(destination,animated: true)

故事板:
首先,您必须为视图设置标识符。在下面的屏幕截图中,您可以看到输入标识符的位置。

之后,您可以使用以下代码创建“目的地”并将其推送到导航控制器:

let storyboard = UIStoryboard(name: "Main",bundle: Bundle.main)
let destination = storyboard.instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
navigationController?.pushViewController(destination,animated: true)

Segue公司:
首先,您必须为您的段落设置一个标识符,如下所示:

performSegue(withIdentifier: "segue",sender: self)

override func prepare(for segue: UIStoryboardSegue,sender: Any?) {
    if segue.identifier == "segue" {
        // Setup new view controller
    }
}

编辑:为Swift 3.x更新

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读