Objective-c – Using performSelector:withObject:afterDelay: with non-object parameters

cocoaiphoneobjective c

I want to invoke setEditing:animated: on a table view with a slight delay. Normally, I'd use performSelector:withObject:afterDelay: but

  1. pSwOaD only accepts one parameter
  2. the second parameter to setEditing:animated: is a primitive BOOL – not an object

In the past I would create a dummy method in my own class, like setTableAnimated and then call [self performSelector:@selector(setTableAnimated) withObject:nil afterDelay:0.1f but that feels kludgy to me.

Is there a better way to do it?

Best Answer

Why not use a dispatch_queue ?

  double delayInSeconds = 2.0;
  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
      [tableView setEditing …];
  });