【发布时间】:2016-05-18 22:46:19
【问题描述】:
我在 VC 中有 3 个按钮,都连接到 IBAction 函数。其中两个工作正常,但提交按钮根本不会触发。
我已确保已启用用户交互。我也尝试添加 sender: AnyObject 作为参数并将函数重新连接到按钮,但仍然没有运气。我也清理了项目。我对发生的事情感到非常困惑。
按钮的可访问性:
这是每个 IBAction 函数的代码:
@IBAction func captureImage(){
self.saveVideoVar = false
let imageFromSource = UIImagePickerController()
imageFromSource.delegate = self
imageFromSource.allowsEditing = false
//if there is a camera
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
imageFromSource.sourceType = UIImagePickerControllerSourceType.Camera
self.presentViewController(imageFromSource, animated: true){}
}
else{
let title = "Error"
let message = "Could not load camera"
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil))
presentViewController(alert, animated: true, completion: nil)
}
}
@IBAction func openImageLibrary(){
self.saveVideoVar = false
let imageFromSource = UIImagePickerController()
imageFromSource.delegate = self
imageFromSource.allowsEditing = false
imageFromSource.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
//presents (loads) the library
self.presentViewController(imageFromSource, animated: true){}
}
//code to submit image and video to amazon S3
@IBAction func submitToS3(){
print("x")
if let img : UIImage = imageView.image! as UIImage{
let path = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("image.png")
let imageData: NSData = UIImagePNGRepresentation(img)!
imageData.writeToFile(path as String, atomically: true)
// once the image is saved we can use the path to create a local fileurl
let url:NSURL = NSURL(fileURLWithPath: path as String)
nwyt.uploadS3(url)
}
}
天啊!我觉得我好笨。有一个重复的屏幕我忘记删除了,它看起来完全一样,但不是正在显示的那个。我要在一个小时内删除它。以下是问题:
【问题讨论】:
-
我怀疑提交按钮不可触摸..你能检查一下..
-
您的意思是在按钮的“辅助功能”部分吗?我更新了我的帖子显示启用了用户交互
标签: ios swift function uibutton ibaction