我在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)
}
}
我的上帝啊!我觉得我好笨。有一个我忘记删除的重复屏幕看起来完全一样,但不是正在显示的屏幕。我将在一小时内将其删除。以下是问题所在:
答案 0 :(得分:2)
通过设置按钮的背景颜色进行检查,以便了解是否有任何视图在按钮上方。
答案 1 :(得分:0)
试试这个:
//code to submit image and video to amazon S3
@IBAction func submitToS3(sender:UIButton){
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)
}
}
似乎缺少回调参数。应该管用。手指交叉!!
请检查属性检查器中的已启用属性!
检查按钮名称!
创建一个新按钮和新方法。尝试并勾住。我遇到过这种问题。如果您使用的是xCode 7,则可能是xCode问题。
答案 2 :(得分:0)
我可以看到“submitToS3:”中有一个额外的“:”,这意味着函数submitToS3应该有一个参数,这不是你的情况。
为了解决这个问题,只需删除submitToS3链接,然后将“提交”按钮拖放到控制器上方的黄色图标,并将其链接到“submitToS3”(您应该在那里看到它)。回顾收到的操作视图时,您不应该看到“:”