我在 A
类中,我想调用 B
类中的方法,我该怎么做。
NSTimer* timer=[NSTimer scheduledTimerWithTimeInterval:4 target:[A class] selector:@selector(method2) userInfo:nil repeats:YES];
但是,方法 method2
没有被调用。如何解决这个问题?
最佳答案
A *objectA = [[A alloc] init];
B *objectB = [[B alloc] init];
[NSTimer scheduledTimerWithTimeInterval:4.0f target:objectB selector:@selector(method2) userInfo:nil repeats:YES];
你必须把它想象成一个方法调用。每 5 秒执行的内容如下所示:
[objectB method2];
在这种情况下,实际的“objectA”并不重要,只要它的“存在”没有被释放即可。
关于ios - 如何使用 scheduledTimerWithTimeInterval 从另一个类调用方法 - 初学者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32222360/