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