使用imagePicker将拾取的图像附加到数组中

时间:2016-05-23 08:55:01

标签: arrays swift uiimagepickercontroller

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {            
        selectedImageArray.append(pickedImage)            
    }        
    dismissViewControllerAnimated(true, completion: nil)        
}

我希望将选中的图像放入selectedImageArray中,但是没有得到图像。

1 个答案:

答案 0 :(得分:0)

要获取已选择的图像,您必须使用 NSMutableArray

创建一个公共数组并在其中添加对象。

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
    // assign pickup image into varibale
    var selectedimage : UIImage!
    if let editedImage = info[UIImagePickerControllerEditedImage] as? UIImage
    {
        selectedimage = editedImage
    }
    else
    {
        selectedimage = info[UIImagePickerControllerOriginalImage] as? UIImage
    }
    self.testArray.addObject(selectedimage)
}