开发者

When use NSTimer in classA then can't call any method from other place

Here is a code I call to run timer for calling "tick:" method in classA (it calls NOT in main thread):

    - (id)init {

        self = [super init];

        if (self != nil) {

        self.timer = [NSTimer scheduledTimerWithTimeInterval:2.0f 
target:self selector:@selector(tick:) userInfo:nil repeats:YES];

        NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
        [currentRunLoop run];
        }

      return self;
    }

And timer works great. But when try to access to "doSomething" method (the same instance of class classA) in the same thread then method "doSomething"开发者_如何学JAVA does't calls.

Why? How to fix the problem?


How selector doSomething: is called?

Anyway you should try [classAinstance performSelectorOnMainThread:@selector(doSomethingOnMainThread:) waitUntilDone:YESORNO];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜