我使用LJWebImage示例項目,其中,我發現從github上的以下鏈接https://github.com/likumb/LJWebImage。項目,類似於SDWebImage.I成功導入示例項目到我的項目中。我正在使用collectionView填充plist中包含多個url鏈接的圖像。我試圖將collectionView選中的cellimage傳遞給我的imageView,但沒有運氣,因此對於。請有人指點我的方向。我的部分collectionView代碼如下。在Swift中的URL圖像
在此先感謝。
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
}
}
}
請顯示準備從第一個vc到第二個vc的繼續或導航的代碼。 –
@Nirav D collectionView和imageView在相同的viewController.i我沒有使用segue ..感謝 – Joe
然後訪問plist而不是應用程序數組是什麼意思。 –