0

据我所知,我有以下两个陈述本质上应该做完全相同的事情:

//[NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(hideSuccessImageFromAllScreen:) userInfo:nil repeats:NO];
[self performSelector:@selector(hideSuccessImageFromAllScreen:) withObject:nil afterDelay:2.0];

其次是

-(void)hideSuccessImageFromAllScreen:(NSTimer *)timer{...

perform 选择器方法运行得很好,选择器被执行。但是,如果我取消注释第一行并注释掉第二行,则选择器永远不会触发。我究竟做错了什么?我必须手动启动计时器吗?

谢谢!

4

1 回答 1

6

您要么必须手动启动计时器,要么使用+[NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:],它将为您自动启动它:

[NSTimer scheduledTimerWithTimeInterval:2.0
                                 target:self
                              selector:@selector(hideSuccessImageFromAllScreen:)
                              userInfo:nil
                               repeats:NO];
于 2012-09-29T19:45:14.407 回答