我想在屏幕上顯示警報時暫停屏幕,然後在警報解除時撤消暫停。我會怎麼做? 這裏是我的視圖控制器:當屏幕上出現警告時,我該如何暫停應用程序?
- (void)viewDidLoad
{NSLog(@"viewDidLoad");
[super viewDidLoad];
[self generate];
[self.answer becomeFirstResponder];
UIAlertView *alert;
{alert = [[UIAlertView alloc]
initWithTitle:@"Welcome to iCanMultiply!"
message:@"Tap 'Start' to start the game"
delegate: self
cancelButtonTitle:@"Start"
otherButtonTitles: nil];
}
[alert show];
[alert release];
alertTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(showAlert) userInfo:nil repeats:YES];
}
-(void)showAlert {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Game Over"
message:@"You ran out of time"
delegate:self
cancelButtonTitle:@"Try Again"
otherButtonTitles: nil];
[alert show];
[alert release];
}
- (IBAction)submit:(id)sender {
int num = [answer.text intValue];
UIAlertView *alert;
if (num == label.tag)
{
NSUInteger messageCount = [messagesCorrect count];
int randomMessageIndex = arc4random() % messageCount;
alert = [[UIAlertView alloc]
initWithTitle:@"Correct!"
message:[messagesCorrect objectAtIndex:randomMessageIndex]
delegate:self
cancelButtonTitle:@"Next Question"
otherButtonTitles: nil];
alert.tag = 1;
} else
{
NSUInteger messageCount = [messagesIncorrect count];
int randomMessageIndex = arc4random() % messageCount;
alert = [[UIAlertView alloc]
initWithTitle:@"Wrong!"
message:[messagesIncorrect objectAtIndex:randomMessageIndex]
delegate:self
cancelButtonTitle:@"Try Again"
otherButtonTitles: nil];
}
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 1)
{
[self generate];
answer.text = @"";
}
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
}
請注意,我的應用程序委託是一樣的是,當我第一次開始對應用程序的工作。
是你做了,謝謝你。 –