首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

无法将正确的数据从嵌入在UITableView中的UICollectionView发送到ViewController Swift3

在Swift3中,将正确的数据从嵌入在UITableView中的UICollectionView发送到ViewController可以通过以下步骤实现:

  1. 首先,确保你的UITableView和UICollectionView已经正确地设置并显示在ViewController上。
  2. 在你的ViewController类中,创建一个变量来存储你想要发送的数据。例如,你可以创建一个名为"selectedData"的变量。
代码语言:swift
复制
var selectedData: Any?
  1. 在你的UITableViewDelegate和UICollectionViewDelegate方法中,当用户选择某个单元格时,将选中的数据赋值给"selectedData"变量。
代码语言:swift
复制
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    selectedData = yourDataArray[indexPath.row]
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    selectedData = yourDataArray[indexPath.item]
}
  1. 在你的ViewController中,你可以使用"selectedData"变量来执行任何你想要的操作,例如显示在另一个视图控制器中或者进行进一步的处理。
代码语言:swift
复制
func showSelectedData() {
    if let data = selectedData {
        // 在这里执行你想要的操作,例如显示在另一个视图控制器中
        let detailViewController = DetailViewController()
        detailViewController.data = data
        navigationController?.pushViewController(detailViewController, animated: true)
    }
}

这样,你就可以将正确的数据从嵌入在UITableView中的UICollectionView发送到ViewController了。

对于Swift3中的UITableView和UICollectionView的使用,你可以参考腾讯云的相关文档和示例代码:

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券