Swift中的Url图像
我使用了LJWebImage示例项目,我在github的以下链接中找到了该项目。项目与SDWebImage类似。我已成功将示例项目导入到我的项目中。我正在使用collectionView从plist填充包含大量url链接的图像。我正在尝试将collectionView选定的cellimage传递到我的imageView,但没有成功。请有人给我指一下方向。我的部分collectionView代码如下 提前谢谢Swift中的Url图像,swift,uicollectionview,swift3,Swift,Uicollectionview,Swift3,我使用了LJWebImage示例项目,我在github的以下链接中找到了该项目。项目与SDWebImage类似。我已成功将示例项目导入到我的项目中。我正在使用collectionView从plist填充包含大量url链接的图像。我正在尝试将collectionView选定的cellimage传递到我的imageView,但没有成功。请有人给我指一下方向。我的部分collectionView代码如下 提前谢谢 let apps: NSArray = AppInfo.appInfo() @IBOu
let apps: NSArray = AppInfo.appInfo()
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView!.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - CollectionView data source
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return apps.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath) as! Cell
cell.app = apps[indexPath.row] as? AppInfo
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let filePath = Bundle.main.path(forResource: "apps", ofType: "plist"),
let image = UIImage(contentsOfFile: filePath) {
imageView.contentMode = .scaleAspectFit
imageView.image = image
}
}
}
您可以使用indexPath从数据源数组中检索相应的应用程序对象
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let app = apps[indexPath.row] as? AppInfo else { return }
guard let image = UIImage(contentsOfFile: app.filePath) else { return }
imageView.contentMode = .scaleAspectFit
imageView.image = image
}
或者您可以使用indexPath检索单元格,并从其imageView中获取图像
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let cell = collectionView.cellForItem(at: indexPath) as? Cell else { return }
imageView.contentMode = .scaleAspectFit
imageView.image = cell.imageView.image
}
请显示从第一个vc到第二个vc的“准备segue”或“导航”代码。@Nirav D collectionView和imageView在同一个viewController中。我根本没有使用segue..感谢访问plist而不是apps Array的意义。@Nirav D。我试图使用应用程序阵列。但是,我不知道如何使用它。你能详细说明一下吗。谢谢