UITableViewCell selection Storyboard segue is slow - double tapping works though

前端 未结 2 539
清歌不尽
清歌不尽 2020-12-10 11:26

I have a UITableViewController in a Storyboard. I have the selection of my UITableViewCell prototype trigger a segue to present another controller. The presentation itself i

相关标签:
2条回答
  • 2020-12-10 11:46

    In my case, the solution ended up being to call performSegue manually from didSelectRow on the main queue using GCD instead of using the UITableViewCell selection outlet in Storyboard.

    - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      dispatch_async(dispatch_get_main_queue(), ^{
        [self performSegueWithIdentifier:kShowDetailSegue
                              sender:nil];
      });
    }
    

    I'm not sure why this became necessary- certainly you'd think that the selection outlet in Storyboard would operate on the main queue, but maybe it is an iOS 8 bug.

    0 讨论(0)
  • 2020-12-10 12:00

    Carlos Vela is right, the bug is accouring only when UITableViewCell selection is none and only on real device. Waking up CFRunLoop after selection solves the problem and this led me to this "universal" workaround (which is a category on UITableViewCell).

    UPDATE: it works perfectly under iOS7 but under iOS8 it brokes transparent UITableViewCell background (it will be white).

    #import <objc/runtime.h>
    
    @implementation UITableViewCell (WYDoubleTapFix)
    
    + (void)load
    {
        Method original, swizzled;
    
        original = class_getInstanceMethod([UITableViewCell class], @selector(setSelected:animated:));
        swizzled = class_getInstanceMethod([UITableViewCell class], @selector(mySetSelected:animated:));
        method_exchangeImplementations(original, swizzled);
    }
    
    - (void)mySetSelected:(BOOL)selected animated:(BOOL)animated
    {
        [self mySetSelected:selected animated:animated];
        CFRunLoopWakeUp(CFRunLoopGetCurrent());
    }
    
    @end
    
    0 讨论(0)
提交回复
热议问题