私はカメラから得たすべての画像で配列を取得しました。それらは私のcoreDataに保存されています。ユーザーが新しい写真を撮ると、写真はコアデータに保存され、次に通常の配列データがcoreDataイメージに置き換えられます。コレクションビューに戻ると、最初と最後の画像だけが表示されます。画像を印刷すると、画像が[indexpath.item]出力されます。しかし、彼らは細胞に示されていません。私はセル内のimageViewのカスタムクラスを持っており、imageViewには制約があるため、イメージは可視領域から外れることはありません。 私はあなたの助けによってこの問題を解決することを楽しみにしています。ありがとうございました。ここで画像はコレクションビューのセルに表示されません。 iOS(スウィフト)
は、カメラキャッチからのコードです:
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 –