【发布时间】:2016-06-23 20:47:14
【问题描述】:
我们正在尝试创建一个集合视图。在每个单元格中,用户可以选择图像并将文本输入文本字段。我们注意到,在添加四个单元格后,当我们添加一个新单元格时,文本字段已经填充了之前单元格的信息。在我们的代码中,我们从不以编程方式填充文本字段(一开始是空的),我们允许用户这样做。有什么建议吗?
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Image", forIndexPath: indexPath) as! CollectionViewCell
cell.deleteButton?.addTarget(self, action: #selector(AddNewItem.xButtonPressed(_:)), forControlEvents: UIControlEvents.TouchUpInside)
cell.deleteButton?.layer.setValue(indexPath.row, forKey: "index")
let item = items[indexPath.item]
let path = getDocumentsDirectory().stringByAppendingPathComponent(item.image)
cell.imageView.image = UIImage(contentsOfFile: path)
cell.imageView.layer.borderColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3).CGColor
cell.imageView.layer.borderWidth = 2
cell.layer.cornerRadius = 7
return cell
}
【问题讨论】:
标签: ios xcode swift collectionview