在我的项目中实现它之前,我已经创建了一个带有计时器的测试应用程序。这是我第一次使用计时器。但问题是当我使用 实现计时器时[NSTimer timerWithTimeInterval: target: selector: userInfo: repeats: ];
,它不起作用。这是我的代码,接口:
@interface uialertViewController : UIViewController
{
NSTimer *timer;
}
-(void)displayAlert;
-(void)hideandview;
@end
执行:
@implementation uialertViewController
- (void)viewDidLoad {
[self displayAlert];
[super viewDidLoad];
}
-(void)displayAlert{
timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(hideandview) userInfo:nil repeats:NO];
alert = [[UIAlertView alloc] initWithTitle:@"testing" message:@"hi hi hi" delegate:nil cancelButtonTitle:@"continue" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
}
-(void)hideandview{
NSLog(@"triggered");
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
[self displayAlert];
}
@end
然后我改变 [NSTimer timerWithTimeInterval: target: selector: userInfo: repeats: ];
了 [NSTimer scheduledTimerWithTimeInterval: target: selector:userInfo: repeats: ];
,它正在工作。有什么问题timerWithTimeInterval:
?我在第一次实施中遗漏了什么吗?提前致谢。