Con*_*rry 5 ios uicollectionview swift
Swift 编程新手,我的错误的原因是什么,我该如何解决?非常感谢。
导入 UIKit
导入照片
类 PhotosViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource , UICollectionViewDelegateFlowLayout, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
@IBOutlet 弱 var myCollectionView:UICollectionView!
var imagesArray = [UIImage]()
覆盖 func viewDidLoad(){
super.viewDidLoad()
myCollectionView.delegate = self
myCollectionView.dataSource = self
}
@IBAction func addPhoto(_ sender: AnyObject) {
让选择器:UIImagePickerController = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
选择器.delegate = self
picker.allowsEditing = false
self.present(选择器,动画:true,完成:nil)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! 细胞
cell.configurecell(imagesArray[indexPath.row])
返回单元格
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection 部分: Int) -> Int {
返回 imagesArray.count
}
func imagePickerController(_picker: UIImagePickerController, didFinishPickingMediaWithInfo 信息: [String : Any]) {
if let pickimage = (info[UIImagePickerControllerOriginalImage] as? UIImage){
imagesArray = [pickedimage,pickedimage,pickedimage]//将三个选定的图像存储在您的数组中
myCollectionView.reloadData()
}
解雇(动画:真实,完成:无)
}
}
| 归档时间: |
|
| 查看次数: |
4537 次 |
| 最近记录: |