IOS 9 - UIButton on subview does not trigger IBAction output

I struggled with this for a couple of days and could not determine the exact cause of my problem, as the name says, UIButton on the subtitle does not start the IBAction output when it “clicks”,

Let me clarify, I'm working on a tinder-like application, where I use this third-party library . I implement individual views that have buttons and other controllers. The buttons in these "Maps" do not trigger their IBAction exits.

As far as I can tell, the library does the following:

Stacks 3 "DraggableViews" on top of each other, each draggable view has 2 child views, one of them is the content view in which my custom view lives, and the other is the overlay view, which has the top view. Drag-and-drop views use two gesture recognizers to do their job, the first of which is a click gesture that calls the delegate method to handle tap events on the map (in their example, this is used to display the browser view). The second gesture is the panorama gesture used to implement the saber functionality.

I did my homework and tried several different solutions, but I can't get IBAction to shoot. I tried the following:

  • Use the parent view of DraggableViews to turn off gesture recognizer when a touch event is fired on a button. - It works (gesture is disabled), but IBAction does not start. in the case of pan gestures, I can no longer “scroll” the map when I touch the button, and the “tap” event does not hit the breakpoint in the delegate method mentioned above. In the user interface, my button responds to touch when it comes to life, but its exit in the view controller does not hit the breakpoint. I disabled it like this:

    //- Called when each DraggableView is visible (not called for view at index 0, but works alright for debugging in the mean time)
    func koloda(koloda: KolodaView, didShowCardAtIndex index: UInt) {
     let subviews = koloda.subviews
     for subview in subviews {
        if let recognizers = subview.gestureRecognizers {
            for gesture in recognizers {
                if gesture is UIPanGestureRecognizer || gesture is UITapGestureRecognizer{
                    //- Also tried setting this to false but nothing.
                    gesture.cancelsTouchesInView = false 
                    gesture.delegate = self
                }
            }
        }
    }
    
    //- On the gestureRecognizerDelegate
    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
       if touch.view is UIButton {
         return false
       } else {
         return true
       }
    }
    
  • Implemented a gesture of pressing a button on a button programmatically, On viewDidLoad I add an action to the tap gestures, but this does not cause an exit.

  • userInteractionEnabled ImageView True, , ( , ?).

, userInteractionEnabled.

, , xib, , , :

if let vc = spiViewConntroller {
        return vc.view
    }

!

!

EDIT: , , . , ImageView . - , , .

Koloda , - "StackOverflowDemo". , , ( ) . , , . , , 0 .

, , - , !

.

+4
3

. , , Koloda. vc.view , Koloda , , .

, , Container View Controller. Apple : https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

:

- (void) displayContentController: (UIViewController*) content {
   [self addChildViewController:content];
   content.view.frame = [self frameForContentController];
   [self.view addSubview:self.currentClientView];
   [content didMoveToParentViewController:self];
}
+4

, . , , . , , MVC.

, , View Controller xib - . , , . , , ViewDidLoad (.. ).

Solution: I removed the file owner from lib, created a custom class that inherits from UIView, say MyCustomUIView and moving the view controller logic, its outputs and actions to this class. Then, in the xib file, I linked the content view to MyCustomUIView. However, this solution seems dirty, since I expect the view controller to handle all the logic. You may need to read a little about nib and reusable views.

0
source

All Articles