我有一个UIImagePickerController和2个按钮。当我点击按钮1时,我想设置按钮1的图像。当我点击按钮2时,我想设置按钮2的图像。我已经使用UIImagePickerController成功设置按钮1的图像但是没有这样做按钮2.这是我的代码:
var whichButton: Int = 0
func displayImagePicker(){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
@IBAction func chooseImageOne(sender: AnyObject) {
displayImagePicker()
whichButton = 1
}
@IBAction func chooseImageTwo(sender: AnyObject) {
displayImagePicker()
whichButton = 2
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
self.dismissViewControllerAnimated(true, completion: nil)
if whichButton == 1 {
self.imageOne.setImage(image, forState: UIControlState.Normal)
} else if whichButton == 2 {
self.imageTwo.setImage(image, forState: UIControlState.Normal)
}
}
正如你所看到的,我尝试使用var来跟踪我正在点击的按钮。我不确定我在didFinishPickingImage函数中所做的是对的。我很快乐,如果有人能说出一些亮点,它真的会很棒!提前谢谢
答案 0 :(得分:0)
您的代码功能正确。看起来您的MyOAuth2MethodSecurityExpressionHandler extends OAuth2MethodSecurityExpressionHandler
功能未正确连接,或第二个按钮的ResponseEntity
。您可以使用按钮处理程序或调试器中的print语句轻松检查这一点。
答案 1 :(得分:0)
我亲自在xcode上检查了你的代码及其正确。请查看您是否已将IBOutlet提供给self.imageTwo按钮,并检查IBAction,即touchupInside for imageTwo按钮。否则一切都很好