ios - 如何使用 segue 在下一个 Controller 中显示单元格标题?

标签 ios swift

我有一个 UITableViewController,其标签位于 Storyboard的单元格中。我想在下一个 Controller 的标题中显示所选单元格标签的标题。如何显示标题?

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 8
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.destination is ViewController) {
        //code to showing title of my cell
    }
}

最佳答案

您只需在 if 语句中获取目标 ViewController,如下所示:

//get destination view an set the title
let vc=segue.destination
//set title
vc.title="My Title"

关于ios - 如何使用 segue 在下一个 Controller 中显示单元格标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43983626/

相关文章:

ios - 创建 iOS 开发证书

ios - 如何使用压缩算法进行图像压缩,即 LZ4 、 LZMA 、 ZLIB swift

ios - 在 IOS 中,我们可以在 UITableView 和 UITableView Cell 的背景中设置图像吗?

swift - 如何按元素相乘两个数组

ios - 类数组中的过滤结果(Swift 3)

ios - AVSpeechSynthesizer 只工作一次

ios - AVCaptureConnection isVideoMinFrameDurationSupported 为 false?

ios - 对许多包含数字的 NSArray 进行排序

ios - 如何获取 UITextField 相对于 UIScreen 的原点 y 位置?

swift - 单独类中的数据源 - 未调用 cellForRowAt indexPath