0

Does anyone have any idea why I can't register this UIButton being touched?

enter image description here

enter image description here

The function this should fire is:

@IBAction func buttonPressed(sender: AnyObject) {
    print(321)
}

Maybe one thing to know about this view is that it's a ViewController holding a UIScrollView that is holding 3 ViewControllers itself that in turn is holding the UIButton.

So:

ViewController --> UIScrollView --> ViewController --> UIButton

Here's how I load those 2nd ViewControllers in my UIScrollView:

override func viewDidLoad() {
    self.loadSuggestionCards()
}

func loadSuggestionCards() {
    let screenSize: CGRect = UIScreen.mainScreen().bounds
    let screenWidth = screenSize.width
    let screenHeight = screenSize.height

    self.scrollView.contentSize = CGSize(width:(Int(screenWidth)*itemList.count), height: Int(screenHeight))

    self.scrollView.clipsToBounds = true

    var viewXOffset : CGFloat = 0

    for item in self.itemList {
        let newViewController = ItemSuggestionsView()
        newViewController.item = item
        let view = newViewController.view
        view.frame = CGRectMake(viewXOffset, 0, screenWidth, screenHeight)
        self.scrollView.addSubview(view)
        viewXOffset = viewXOffset + screenWidth
    }

    self.updateProgressView()
}
Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67
  • Check user interaction is enabled or not – Krunal Feb 21 '17 at 10:31
  • Wait wait wait. You are loading ViewControllers inside ViewController? – NSNoob Feb 21 '17 at 10:32
  • User interaction is enabled. @NSNoob yes I am. No good? – Rutger Huijsmans Feb 21 '17 at 10:33
  • You should be using [ContainerView](http://stackoverflow.com/questions/23399061/how-to-add-a-subview-that-has-its-own-uiviewcontroller-in-objective-c/23403979#23403979) or something instead of ScrollView here – NSNoob Feb 21 '17 at 10:33
  • @RutgerHuijsmans May be button is not inside the contentSize of scrollView, Increase the height for scrollView contentSize probably solved your problem. – Nirav D Feb 21 '17 at 10:38
  • @NiravD I can scroll the scrollView even below the button. I set the contensize to equal the height of the screen – Rutger Huijsmans Feb 21 '17 at 10:41
  • I somewhat understand your problem, i think you are trying to do action on button which is not in same controller , for achieving this you have to write on protocol in childcontroller and implement there in parent controller & call to childviewcontroller method for doing action. – Mukesh Lokare Feb 21 '17 at 10:52
  • If you are doing same let me know i'll tell you exactly what to do in answer. – Mukesh Lokare Feb 21 '17 at 10:52
  • NiravD ok I'll give it a try. @Mukesh no that's not the case. My IBAction is in the same viewController as my buttons – Rutger Huijsmans Feb 21 '17 at 10:55
  • @RutgerHuijsmans check the "Clip To Bounds" in inspect property of UIButton see the button is showing or not. – Maishi Wadhwani Feb 21 '17 at 11:59
  • @MaishiSajnani I've tried adding Clip To Bounds but everything is showing up accordingly. It doesn't to affect my problem – Rutger Huijsmans Feb 22 '17 at 02:24

1 Answers1

1

Check whether user interaction of button is enabled or not.

Anuraj
  • 1,242
  • 10
  • 25