Search code examples
ios64-bituser-interactionperformselector

iOS: setUserInteractionEnabled with performSelector does not work on 64 bit


If you try

 [self.view performSelector:@selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:YES] afterDelay:2];

on the 64 bit iPhone (even on the simulator) user interaction will be disabled. Regardless of any previous state.

This line works on 32 bit iPhones though.

Is this a bug in the OS? Am I missing something?


Solution

  • setUserInteractionEnabled: expects a BOOL parameter but you are sending it a NSNumber. Your code worked just by chance in the 32-bit environment, but

     [self.view performSelector:@selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:NO] afterDelay:2];
    

    does not reset the property to NO even on 32-bit (when I tested it), so it does not really work.

    The easiest method to solve this problem is to use GCD:

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.view.userInteractionEnabled = YES;
    });