UITableView and presentViewController takes 2 clicks to display UITableView and presentViewController takes 2 clicks to display ios ios

UITableView and presentViewController takes 2 clicks to display

Check this out: https://devforums.apple.com/thread/201431If you don't want to read it all - the solution for some people (including me) was to make the presentViewController call explicitly on the main thread:

dispatch_async(dispatch_get_main_queue(), ^{    [self presentViewController:myVC animated:YES completion:nil];});

Probably iOS7 is messing up the threads in didSelectRowAtIndexPath.

After much more debugging, I was able to determine it wasn't the view controller, but something to do with the the didSelectRowAtIndexPath and presentViewController. It started happening to other views I was presenting also, and not reliably. I also tried using if/else instead of switch with no help.

Ultimately I found this solution was able to fix it, but I'm not entirely sure why. By using the performSelector with no delay, all the views load instantly (perhaps faster than without it?) and reliably every time.

It isn't as clean of code, but it does reliably work now. Am still curious why this is needed.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {        switch(indexPath.row){        case 0:            [self performSelector:@selector(load0:) withObject:nil afterDelay:0];            break;        case 1:            [self performSelector:@selector(load1:) withObject:nil afterDelay:0];            break;        case 2:            [self performSelector:@selector(load2:) withObject:nil afterDelay:0];            break;        ...    }}-(void)load0:(id)sender {     [self presentViewController:self.delegateRef.zonesViewController animated:YES completion:nil];}-(void)load1:(id)sender {     [self presentViewController:self.delegateRef.sensorsViewController animated:YES completion:nil];}-(void)load2:(id)sender {     [self presentViewController:self.delegateRef.savedRidesViewController animated:YES completion:nil];}

This is an actual bug in presentViewController:animated:completion:. See my answer with the proper workaround here: https://stackoverflow.com/a/30787046/1812788