У меня есть массив со всеми изображениями, которые я получил от камеры. Они сохраняются в моей базе данных. Если пользователь берет новую фотографию, фотография будет сохранена в основных данных, а затем я заменю обычные данные массива изображениями coreData. Поэтому, если я вернусь к представлению коллекции, отобразится только первое и последнее изображение. Когда я печатаю изображения [indexpath.item], я получил изображения. Но они не показаны в клетках. У меня есть собственный класс для imageView в ячейке, и у ImageView есть ограничения, поэтому изображение не может быть вне видимой области, я думаю. Я с нетерпением жду этой проблемы с вашей помощью. Спасибо.Изображения arent показаны в моих коллекциях. iOS (swift)
Вот код с уловом камеры:
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
photoImage.image = image
print(images)
addPhotoLabel.removeFromSuperview()
if(isEdit == false)
{
let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
let entinity = NSEntityDescription.entityForName("Image", inManagedObjectContext: context)
let newImage = Image(entity: entinity!, insertIntoManagedObjectContext: context)
newImage.image = UIImageJPEGRepresentation(image, 1)
do {
try context.save()
} catch let error as NSError {
print(error)
}
images.removeAll()
let request = NSFetchRequest()
request.entity = entinity
let fetched = try? context.executeFetchRequest(request)
if fetched != nil {
let imagesS = fetched!.map { UIImage(data: ($0 as! Image).image!)}
images.appendContentsOf(imagesS)
}
}
self.dismissViewControllerAnimated(true, completion: nil);
}
А вот код был я создать ячейку:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
//1
let cell : FlickrPhotoCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! FlickrPhotoCell
if(searchBarActive == true)
{
cell.nameLabel.text = researchResults[indexPath.item]
cell.imageView.image = sFunc_imageFixOrientation(resultImages[indexPath.item])
}
else
{
cell.nameLabel.text = names[indexPath.item]
let imageT : UIImage = images[indexPath.item]!
cell.imageView.image = images[indexPath.item]
print(images[indexPath.item])
}
cell.nameLabel.hidden = false
cell.frame.size = CGSizeMake(UIScreen.mainScreen().bounds.width/2 , UIScreen.mainScreen().bounds.width/2)
cell.imageView.frame = cell.frame
cell.backgroundColor = UIColor.clearColor()
cell.layer.borderColor = themeColor.CGColor
cell.layer.borderWidth = 4
cell.layer.cornerRadius = CGFloat(10.0)
cell.placeHolderName.frame.size = CGSize(width: cell.frame.width, height: cell.frame.height/4)
return cell
}
Пожалуйста, покажите нам код, который вы попробовали. –
вот исходный код, если вам нужно больше просто спросить, спасибо @NDoc –