Search code examples
iosinterface-buildergestureiboutlet

Partial Swipe to Pop Breaks Interface Builder UI


When I tap on a cell in a table view in my app, I present another view controller. This view controller is initialized from a nib with the initWithNibName:bundle: method, and I have a number of UIButtons with IBOutlets that I have configured through interface builder.

90% of the time, everything works great. I can present and dismiss the view controller as expected. Dismiss can happen with either a button on the navigation bar or with the swipe gesture.

The problem:

If I start the swipe to dismiss gesture but then return my finger to the left side of the screen and allow the view controller to remain in place, all of my references to the outlets are broken. The button's actions still send valid calls to my code, and their connected methods are being called, but any attempts to update the same UI elements fail.

Edit: I suspect the view is being partially deallocated or something. (Dealloc gets called when the swipe to pop gesture starts.


Solution

  • The answer turned out to be nothing to do with Interface Builder. My UI was supposed to update in response to a delegate callback method like this:

    - (IBAction)didPressButton {
        manager.signInUser(self.user);
    }
    
    //Delegate Method
    - (void)managerDidSignInWithSuccess {
        // Update UI
    }
    

    I was assigning the delegate in the init method, which was getting called and re-assigned when I partially swiped the VC away. Moving the assignment to the viewDidLoad did the trick and everything now works as expected.

    -(id)init {
        if (self = [super init]) {
            manager.delegate = self;
            //other init stuff
        }
    }
    

    should have been:

    -(void)viewDidLoad {
        manager.delegate = self;
    }