performSelector:withObject:afterDelay: not making call

前端 未结 4 2060
情书的邮戳
情书的邮戳 2021-02-19 00:45

in a method, i want to call a method after n seconds:

    self.toolBarState = [NSNumber numberWithInt:1];
    [self changeButtonNames];
    [self drawMap];
    [         


        
4条回答
  •  轮回少年
    2021-02-19 01:14

    I ran into this same issue, and by necessity I solve it slightly different from the accepted answer. Notice I wanted my delay and selectors to be variables? Using a block allows me to stay within my current method.

    dispatch_async(dispatch_get_main_queue(), ^{
           [self performSelector:loopSelector withObject:nil afterDelay:cycleTime];
    });  
    

    By the way, this is definitely a threading issue. The documentation for performSelector:withObject:afterDelay: states that this will be performed on the current thread after the delay, but sometimes that thread's run loop is no longer active.

    A more detailed discussion on the subject can be found here

提交回复
热议问题