0
我試圖通過segue傳遞數據(字典的值[「IDD」])。 (XCODE 7.2)Swift 2從UIcollectionview(indexpath.row)通過segue傳遞數據
這裏我的代碼:
var arrRes = [[String:AnyObject]]()
var dict = [:]
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as! collectionViewCell
var dict = arrRes[indexPath.row]
let newPrice = dict["price"]!.stringByReplacingOccurrencesOfString(".", withString: ",")
cell.lblPrice.text = "€\(newPrice)"
cell.lblTitle.text = dict["title"] as? String
cell.lblBrand.text = dict["brand"] as? String
cell.lblIDD.text = dict["IDD"] as? String
cell.imageView!.image = UIImage(named: "loading.gif") //set placeholder image first.
dispatch_async(dispatch_get_main_queue()) {
cell.imageView!.downloadImageFrom(link: dict["image"] as! String, contentMode: UIViewContentMode.ScaleAspectFit) //set your image from link array.
}
return cell
}
但我不權瞭如何設置賽格瑞的performseguewithidentifier
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "homeDetailSegue")
{
let cell = sender as! UICollectionViewCell
let detailView = segue.destinationViewController as! dettaglio
let dict = arrRes[(self.myCollectionView.indexPathForCell(cell))!]
detailView.setnomeOggetto(arrRes["IDD"] as! String)
}
}
我有tableviews沒有問題,但是這是我的第一次收集查看
可以請別人幫我嗎?
親切的問候 非常感謝你 法比奧
嗨。謝謝你的答案,但可以使用相同的方法用於tableview? 這裏我的例子(它爲實現代碼如下) 覆蓋FUNC prepareForSegue(SEGUE:UIStoryboardSegue,發件人:AnyObject){ 如果(segue.identifier == 「homeDetailSegue」) { 讓datoDaPassare = segue.destinationViewController作爲! dettaglio 讓字典= arrRes [(self.tblJSONHOME.indexPathForSelectedRow?.row)!] datoDaPassare.setnomeOggetto(字典[ 「ID」]作爲!字符串) }} 謝謝 –