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” does’t calls.
Why? How to fix the problem?
How selector
doSomething:is called?Anyway you should try
[classAinstance performSelectorOnMainThread:@selector(doSomethingOnMainThread:) waitUntilDone:YESORNO];