user481610
user481610

Reputation: 3270

UIButton never fires off code in Action

I have the following screen:

enter image description here

The X is the image of a UIButton, I have add the appropriate action to the button. Yet when I click on the button it never fires off the code in the action.

Here is some code:

 @IBAction func CloseProfilePage(sender: AnyObject) {
        self.removeAnimate();    
    }

This is the code that is used to launch the view controller seen:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        let selectedAppointment = self.dayDatasource!.appointmentAtIndex(indexPath.item);
        let profilePageViewController = ProfilePageViewController.init(withAppointment: selectedAppointment);

        profilePageViewController.view.frame = self.view.frame
        self.view.addSubview(profilePageViewController.view)
        profilePageViewController.didMoveToParentViewController(self)

    }

The button is definitely connected in the xib to the action:

enter image description here

When I check in the view hierachy, there isn't anything else on top of the button that would prevent the button but registering clicks. I'm assuming here that the imageView in the UIButton is clickable as its part of the button iteself.

enter image description here

The X in the image is not an image view I added, it is the image view that comes with the UIButton. With that said I've also resorted to the following:

self.profilePageClosePopUpButton.imageView?.userInteractionEnabled = true;

Still the button remains unclickable. Where am I going wrong?

Upvotes: 4

Views: 82

Answers (1)

user481610
user481610

Reputation: 3270

It pains me to say this but I'm only writing a solution here just in case someone in the future struggles with the same issue and maybe this post could help them.

In the view, seen in the image below, I had some how unintentionally switched off User Interaction Enabled in interface builder. Because this was off, all other children didn't have interaction enabled on them and hence why the button was not clickable...

enter image description here

Moral of the story is, check your parent views and make sure their user interaction is enabled as well.

Upvotes: 3

Related Questions