Ich bekam ein Array mit allen Bildern, die ich von der Kamera bekommen habe. Sie sind in meinen coreData gespeichert. Wenn ein Benutzer ein neues Foto macht, wird das Foto in den Core-Daten gespeichert und dann ersetze ich die normalen Array-Daten durch die CoreData-Bilder. Wenn ich also zurück in die Sammlungsansicht gehe, wird nur das erste und das letzte Bild angezeigt. Wenn ich die Bilder [indexpath.item] ausdrucke, habe ich die Bilder bekommen. Aber sie werden nicht in den Zellen gezeigt. Ich habe eine benutzerdefinierte Klasse für die Bildansicht in der Zelle und die Bildansicht hat Einschränkungen, so dass das Bild nicht aus dem sichtbaren Bereich sein kann, denke ich. Ich freue mich darauf, dieses Problem mit Ihrer Hilfe zu lösen. Vielen Dank. HierBilder von Array arent in UICollectionview gezeigt
ist der Code von der Kamera Haken:
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);
}
und der Code wurde i erstellen die Zelle:
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]
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
}
Frag mich bitte, wenn Sie mehr Code benötigen. Danke
Mögliches Duplikat von [Bilder werden nicht in meinen collectionviewcells angezeigt. iOS (swift)] (http://stackoverflow.com/questions/38792898/images-arent-shown-in-my-collectionviewcells-iosswift) – ff10
Hier ist, was zu tun ist, wenn niemand Ihre Frage beantwortet. http://stackoverflow.com/help/no-one-answers – ff10