我知道调用一个方法就好像它是无效的一样,即使它有一个返回值(如 printf),但这又如何呢?
[NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(method) userInfo:nil repeats:NO];
我可以让它漂浮在那里而不使用它返回的对象吗?这就像调用 [NSObject alloc] 而不将其分配给指针或任何东西。那是内存泄漏吗?原因是我不想将它分配给一个变量(计时器),因为如果我释放(或自动释放)它会在它触发之前被删除。而且我不想使用 ivar。所以我该怎么做?
编辑:我发现了 [self performSelector:@selector(myMethod) withObject:nil afterDelay:0.3]; 这比使用计时器要好得多。