0
我有一个UICollectionView,我想要保存数据(图像)总是在第一个单元格中,旧数据将走到下一个单元格。所以当我保存一张新照片时,它出现在第一个单元格中,我已经尝试过在cellForRowAtIndexPath中使用indexpath.row == 0 {},但是他只保存在其他单元格中的第一个单元格中。我可以反转保存索引或给它另一种方式?保存数据总是在第一个单元UICollectionView
有没有人有一个想法,我可以做什么?
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return picture.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("BookPicCell", forIndexPath: indexPath) as! BookPicCell
let cellcore = picture[indexPath.row]
if indexPath.row == 0 {
cell.BookImage.image = UIImage(contentsOfFile: cellcore.foto!)
}
return cell
}
感谢您的帮助。
我使用的核心数据中的数据进行排序,并且将图像保存为字符串,所以我有这样的代码'让newpic = NSEntityDescription.insertNewObject ForEntityForName(“EveryPicture”,inManagedObjectContext:self.mgdContext)as! EveryPicture newpic.everyfoto?.insert(bildPfad,atIndex:0)'带插入时出现无法将字符串转换为typ字符的错误。我从来没有听过字符我可以转换吗? – Hindus
如果你知道它们是字符串类型,你可以通过对编译器更精确来检查你的转换是否失败。使用: 让picturesArray:[String] = ... as! [串]。这样你就知道你是否有一个String或其他的数组。 – Emptyless