美文网首页
[每日学习笔记]tableView点击切换页面

[每日学习笔记]tableView点击切换页面

作者: 帅气的昵称啊点 | 来源:发表于2017-12-11 00:17 被阅读8次

目标:点击tableView上的某一条,可以切换到对应页面(参考微信点击列表进入聊天页面)

问题点:tableView小写的,是系统的,不是自己定义的

步骤:

1.在sb 站住ctrl 拖拽一条 到要显示的viewCtrol上,

2.选中在两者间生成的连接,在右侧的Attrubit inspector的indinfier命名为 xx

3.在tableViewController中的prepare函数中先判断 segue.identifier == xx,//是通过该方式切换过来的

4.定义cell : let cell = sender as? UITableViewCell

5.在tableView中找到所点击的cell的 index

guard let index = tableView.indexPath(for: cell) else{

fatalError("cell index error")

}

6.根据index 从数据中找到点击的数据:let selectItem = listData[index.row]

7.定义要切换页面的viewController,并在sb中指定,在代码中定义该viewController

let detailview = segue.destination as? DetailViewController

8.在要切换的页面中定义数据,把选择的数据赋值给他

detailview.selectlistData = selectItem

9.在要切换的页面使用该数据进行显示

相关文章

网友评论

      本文标题:[每日学习笔记]tableView点击切换页面

      本文链接:https://www.haomeiwen.com/subject/qcsbixtx.html