获取TableView中cell中的label的text出错!
//通过唯一表示符搜索
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//获取视图
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("content") as! ViewController
//获取当前点击的cell
let cellIndex = tableView .cellForRowAtIndexPath(indexPath)
//给标题赋值
viewController.rowIndex = "\(cellIndex?.detailTextLabel?.text)"
//跳转压栈
self.navigationController?.pushViewController(viewController, animated: true)
}
获取到的结果是空的,nil。请问是我获取的方式不对还是思路不对呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般思路应该是这样的:你的 UITableView 需要展示的数据是放在一个 NSArray 类似的容器中,点击某个 Cell 时获取这个 Cell 对应的数据,是在 UITableView 点击 Cell 的回调方法中获取这个 Cell 的 IndexPath,再用这个 IndexPath 去 NSArray 里取得数据,而不是直接从 Cell 上拿数据。
你用的是UItableviewCell吗?
可以通过上诉两个方法获取!