4

I have 3 buttons in a VC, all hooked up to IBAction functions. Two of them work fine but the Submit button simply simply won't trigger.

I have made sure User Interaction is enabled. I have also tried adding sender: AnyObject as a parameter and re-hooking up the function to the button but still no luck. I have also cleaned the project. I am very baffled as to what is going on.

Here is how the VC looks: enter image description here

Hooking the buttons up: enter image description here

Accessibility of button:

enter image description here

Here is the code for each IBAction func:

@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)

    }

}

Screenshot of control clicking the Submit button: enter image description here

OH MY GOD! I feel stupid. There was a duplicate screen I had forgotten to delete that looked exactly the same but wasn't the one that was being displayed. I'm going to delete this in an hour. Below was the problem:

enter image description here

Mitchell
  • 333
  • 5
  • 20

3 Answers3

2

Check by setting background colors to the buttons so that you can understand whether any view is over the button or not .

Reshmi Majumder
  • 961
  • 4
  • 15
  • I added background colours to the working buttons and the not working one. They appear on Storyboard view but when I run the app, I can't see the background colours. However, two of the buttons still work regardless... – Mitchell Feb 09 '16 at 05:00
  • 1
    That means some other view i.e. a dynamic view is over the buttons so you are not able to click them. – Reshmi Majumder Feb 09 '16 at 05:02
  • Ugh I'm an idiot. I added what was the problem to my original question. – Mitchell Feb 09 '16 at 05:07
0

Try this:

//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)
}

}

Seems callback argument was missing. Should work. Finger crossed!!

Please check the enabled property in property inspector!

Check button name!

Create a new button and new method. Try and hook. I had faced this kinda problem. Could be xCode issue if you are using xCode 7.

TechBee
  • 1,897
  • 4
  • 22
  • 46
0

I can see that there is an extra ":" in "submitToS3:", meaning that the function submitToS3 should have an argument, which is not your case.

In order to solve this, just remove the submitToS3 link, and then drag and drop from the Submit button to the yellow icon above in the controller, and link it to the "submitToS3" (you should see it there). When looking back at the Received Actions view, you should not see the ":"

Guy Daher
  • 5,526
  • 5
  • 42
  • 67
  • Ah, that was a result of me having (sender: AnyObject) as a function parameter in the actual code but deleting it when posting here on SO. Anyway, I again tried without (sender: AnyObject), re-hooking it up and it shows the colon was removed but it still does not work :( – Mitchell Feb 09 '16 at 04:35
  • mhmm, I guess you have already tried to just delete the submit button, remove the whole function, and just redo the whole thing? I usually like to do the linking with the assistant editor with a simple drag and drop from the left ot the right, it always work like a charm for me. Can you please right click on the Submit button and put a screenshot of what you see? – Guy Daher Feb 09 '16 at 04:41
  • 1
    Can you try to do that: create a new function named submitToAmazonS3 (or something different than submitToS3 ) and then link your button to that new function. It should work like this. Just as a workaround for now... – Guy Daher Feb 09 '16 at 04:53
  • I tried so now two IBAction functions are connected to it.... still not working :| – Mitchell Feb 09 '16 at 04:58
  • Yes, remove the old connection to submitToS3, so that you only have the connection to submitToAmazonS3 – Guy Daher Feb 09 '16 at 04:59
  • Still no luck... aghhh this is so weird – Mitchell Feb 09 '16 at 05:02
  • Yes very weird... last try: I guess you're deciding that the function is not being hit because you can't see "x" printed in your console. Can you make sure at the bottom left that "All Output" is selected? – Guy Daher Feb 09 '16 at 05:04
  • Ugh I'm an idiot. I added what was the problem to my original question. – Mitchell Feb 09 '16 at 05:08
  • Glad u found out what is the problem :) – Guy Daher Feb 09 '16 at 05:11