ios - 按钮上的 IBAction 功能未触发

标签 ios swift function uibutton ibaction

我在 VC 中有 3 个按钮,都连接到 IBAction 函数。其中两个工作正常,但提交按钮根本不会触发。

我已确保启用了用户交互。我也尝试过添加 sender: AnyObject 作为参数并将函数重新连接到按钮,但仍然没有成功。我也清理了项目。我对发生的事情感到非常困惑。

这是 VC 的样子: enter image description here

连接按钮: enter image description here

按钮的可访问性:

enter image description here

这是每个 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)

    }

}

点击提交按钮的控件截图: enter image description here

天哪!我觉得我好笨。有一个我忘记删除的重复屏幕,它看起来完全一样,但不是显示的那个。我将在一个小时内删除它。下面是问题:

enter image description here

最佳答案

通过为按钮设置背景颜色进行检查,以便您了解是否有任何 View 位于按钮上方。

关于ios - 按钮上的 IBAction 功能未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35283759/

相关文章:

c++ - 检查两个 std::function 是否相等

JavaScript 函数未定义

c++ - 在类构造函数中调用命名 lambda 与调用实际私有(private)函数的优点

ios - 我如何解决 Xcode 的 "This app could not be installed at this time."错误

ios - 调用presentModalView后ViewController viewDidLoad?

swift - 如何在swift中传递可变参数?

ios - 带有图像的自定义后退按钮

ios - 如何更改动态类型以使用不同的文本样式

ios - 获取请求失败 : unacceptable (406) when posting parameters

ios - 屏幕左/左下角的 UINavigationController 和触摸事件