我在VC中有3个按钮,都连接到IBAction函数。其中两个可以正常工作,但提交按钮根本不会触发。
我已经确保启用了用户交互。我还尝试添加sender: AnyObject作为参数,并将函数重新挂接到按钮上,但仍然没有成功。我也清理了这个项目。我对正在发生的事情感到非常困惑。
下面是VC的外观:

将按钮连接起来:

按钮的辅助功能:

下面是每个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)
}
}单击Submit按钮的控件屏幕截图:

我的天啊!我觉得自己很傻。有一个我忘了删除的重复屏幕,它看起来完全一样,但不是正在显示的那个。我要在一小时内删除这篇文章。下面是问题所在:

发布于 2016-02-09 12:53:20
通过设置按钮的背景色进行检查,以便您可以了解是否有任何视图位于按钮上方。
发布于 2016-02-09 12:18:56
试试这个:
//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问题。
发布于 2016-02-09 12:31:52
我可以看到在" submitToS3 :“中有一个额外的":”,这意味着函数submitToS3应该有一个参数,这不是您的情况。
为了解决这个问题,只需删除submitToS3链接,然后从提交按钮拖放到控制器中上面的黄色图标,并将其链接到"submitToS3“(您应该在那里看到它)。当回顾接收到的操作视图时,您应该看不到":“
https://stackoverflow.com/questions/35283759
复制相似问题