gpt4 book ai didi

ios - 将图像从库加载到 UICollection View 。应用程序不断崩溃

转载 作者:行者123 更新时间:2023-11-30 13:18:47 33 4
gpt4 key购买 nike

每次打开具有 Collection View 的 View Controller 时,我都会收到以下消息

[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cameraButtonClicked.' *** First throw call stack: (0x182942db0 0x181fa7f80 0x182942a70 0x18324f6e4 0x187e15de8 0x187f78eb0 0x182866888 0x187f77898 0x1881e4b84 0x1881e9c30 0x1881e9e98 0x1881ea184 0x187ad8be8 0x187c5d640 0x187ad8be8 0x187ad8b64 0x187ac0870 0x187ac09bc 0x187ad8454 0x187ad8084 0x187ad0c20 0x187aa104c 0x19413545c 0x187a9f628 0x1828f909c 0x1828f8b30 0x1828f6830 0x182820c50 0x184108088 0x187b0a088 0x1000bc9e0 0x1823be8b8) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

代码如下

import UIKit
import Photos
private let reuseIdentifier = "PhotoCell"

class AddPhotoViewController: UIViewController , UIImagePickerControllerDelegate ,UINavigationControllerDelegate {

@IBOutlet weak var photoAlbum: UICollectionView!


var assetCollection: PHAssetCollection!
var photosAsset: PHFetchResult!
var assetThumbnailSize: CGSize!

override func viewDidLoad()
{
super.viewDidLoad()
let fetchOptions = PHFetchOptions()

let collection:PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.Album, subtype: .Any, options: fetchOptions)

if let first_Obj:AnyObject = collection.firstObject{
//found the album
self.assetCollection = first_Obj as! PHAssetCollection
}


// Do any additional setup after loading the view.
}

@IBAction func cameraButtonClicked(sender: AnyObject) {

let imagePicker = UIImagePickerController()

if (UIImagePickerController.isSourceTypeAvailable(.Camera)) {

if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {

imagePicker.allowsEditing = true
imagePicker.sourceType = .Camera
imagePicker.cameraCaptureMode = .Photo
presentViewController(imagePicker, animated: false, completion: {} )

} else
{
print("cannot access camera")
}

} else
{
print("cannot access camera")

}
}
override func viewWillAppear(animated: Bool)
{
if let layout = self.photoAlbum!.collectionViewLayout as? UICollectionViewFlowLayout{
let cellSize = layout.itemSize

self.assetThumbnailSize = CGSizeMake(cellSize.width, cellSize.height)
}

//fetch the photos from collection
self.photosAsset = PHAsset.fetchAssetsInAssetCollection(self.assetCollection, options: nil)

self.photoAlbum!.reloadData()


}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int
{
// #warning Incomplete implementation, return the number of sections
return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
// #warning Incomplete implementation, return the number of items
var count: Int = 0

if(self.photosAsset != nil){
count = self.photosAsset.count
}

return count;
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell: PhotoAlbumCollectionViewCell = photoAlbum.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! PhotoAlbumCollectionViewCell


let asset: PHAsset = self.photosAsset[indexPath.item] as! PHAsset

PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: self.assetThumbnailSize, contentMode: .AspectFill, options: nil, resultHandler: {(result, info)in
if let image = result {
cell.setThumbnailImage(image)
}
})

return cell
}
func collectionView(collectinView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 4
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 1
}

// UIImagePickerControllerDelegate Methods
func imagePickerControllerDidCancel(picker: UIImagePickerController)
{
picker.dismissViewControllerAnimated(true, completion: nil)
}

func collectionView(collectionView: UICollectionView, shouldShowMenuForItemAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}

func collectionView(collectionView: UICollectionView, canPerformAction action: Selector, forItemAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) -> Bool
{
return false
}

func collectionView(collectionView: UICollectionView, performAction action: Selector, forItemAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) {

self.dismissViewControllerAnimated(false, completion: nil)

}

}

Collection View 单元格的代码如下

import UIKit

class PhotoAlbumCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var imageView: UIImageView!
func setThumbnailImage(thumbNailImage: UIImage)
{
self.imageView.image = thumbNailImage
}
}

请谁能帮我解决这个问题???

最佳答案

此类不符合键值编码 意味着您的 IBAction 链接存在问题。在 Interface Builder 中,尝试右键单击应调用 cameraButtonClicked 方法的按钮,然后查看是否有警告符号。如果是这样,请删除该链接并重新创建。

关于ios - 将图像从库加载到 UICollection View 。应用程序不断崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37962678/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com