【发布时间】:2017-08-21 10:52:18
【问题描述】:
您好,我是一个初学者,并且停留在一个非常基本的 segue 上!我只是想找出用于发件人的正确语法,例如凉鞋[indexPath.row]sandalName 谢谢
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! shoeCollectionViewCell
let sandalCell = sandals[indexPath.row]
cell.sandalImage.image = UIImage(named: sandalCell["image"]!)
cell.sandalStyleName.text = sandalCell["styleName"]
cell.sandalPrice.text = sandalCell["price"]
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "shoeDetailSegue"{
var detailPage = segue.destination as! shoeDetailViewController
let selectedCell = sender as! UICollectionViewCell
let indexPath = collectionView?.indexPath(for: cell)
detailPage.getName = sandals[indexPath!.row].sandalName
detailPage.getPrice = sandals[indexPath!.row].sandalPrice
detailPage.getImage = sandals[indexPath!.row].sandalImage
}
}
【问题讨论】:
-
向我们展示
sandals数组的声明 -
注意:
var detailPage = segue.destination as! shoeDetailViewController应该是var detailPage = segue.destination as! ShoeDetailViewController忽略错误的变量名称约定。 -
您的字典数组中的值也可能需要进行类型转换。我不知道你是怎么从:
sandalCell["styleName"]到sandals[indexPath!.row].sandalName。一种是使用subscript 访问,另一种是使用properties。这是两个完全不同的东西。 -
它是一个简单的字典。我已经让 collectionView 正常工作并正确填充单元格
标签: ios swift segue uicollectionviewcell uistoryboardsegue