2017-01-18 31 views
0

我有一个可以工作的UIImagePickerController,但我想让用户决定他是拍摄图像还是从库中选取图像。所以这是我的代码试图与警报做到这一点:使用提醒在UIImagePickerController中的图像库或相机之间进行选择

@IBAction func cameraButton(_ sender: UIButton) { 
    picker.allowsEditing = true 
    let alert = UIAlertController(title: "Choose one of the following:", message: "", preferredStyle: UIAlertControllerStyle.alert) 
    alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { action in 
      self.picker.sourceType = .photoLibrary 
    })) 
    alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { action in 
     self.picker.sourceType = .camera 
    })) 
    self.present(alert, animated: true, completion: nil) 
    present(picker, animated: true, completion: nil) 
} 

但是,一旦我点击在警报的行为之一的,什么也没有发生,它只是得到了警告,但没有提出我的选择器

任何帮助表示赞赏

回答

0

我解决它通过这样的行动中呈现:

@IBAction func cameraButton(_ sender: UIButton) { 
    picker.allowsEditing = true 
    let alert = UIAlertController(title: "Choose one of the following:", message: "", preferredStyle: UIAlertControllerStyle.alert) 
    alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { action in 
      self.picker.sourceType = .photoLibrary 
      self.present(self.picker, animated: true, completion: nil) 

    })) 
    alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { action in 
     self.picker.sourceType = .camera 
     self.present(self.picker, animated: true, completion: nil) 

    })) 
    self.present(alert, animated: true, completion: nil) 
} 
相关问题