【问题标题】:collectionview indexPathForSelectedRow [duplicate]collectionview indexPathForSelectedRow [重复]
【发布时间】:2021-09-07 00:55:57
【问题描述】:

所以我在UIViewController 中从使用UITableView 更改为UICollectionView,但我遇到了一个segue 问题。

以前我经常这样做:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        super.prepare(for: segue, sender: sender)
        
        if segue.identifier == "toDetail" {
            
            if let indexPath = tableView.indexPathForSelectedRow {
                let vc = segue.destination as! VehicleViewController
                vc.vehicle = data![indexPath.row]
            }
            
        }
    }

UICollectionView 上的外观应该如何,因为collectionView.indexPathForSelectedRow 不起作用?

【问题讨论】:

    标签: ios swift xcode uicollectionview


    【解决方案1】:

    尝试关注 -

    if let indexPath = collectionView.indexPathsForSelectedItems?.first {
        // Do what you want
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-07
      • 2015-09-17
      • 2012-06-22
      • 1970-01-01
      • 2019-09-17
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多