2017-11-17 5 views
-7
NSTimer scheduledTimerWithTimeInterval:2.0 
           target:self 
           selector:@selector(targetMethod:) 
           userInfo:nil 
           repeats:NO]; 

5分後に「あなたの時間が過ぎました」というメッセージを表示するにはどうすればよいですか?私は、これはあなたを助けるだろうと思いNSTimerを使用してメッセージを表示する

+0

?必要に応じてアラートやアクションシートを表示することができます。他に何があなたの要求です –

答えて

-1
@property NSTimer *timer; 

self.timer = [NSTimer scheduledTimerWithTimeInterval:300.0 
target:self 
selector:@selector(targetMethod) 
userInfo:nil 
repeats:NO]; 


-(void) targetMethod 
{ 
//Your code with msg "you time is over"(Use UILabel) 

// Add lbl to your view 
[self.view addSubview:lbl]; 
lbl.hidden = NO; 
//If you want to hide that msg after 1.0 sec..... 
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 
lbl.hidden = YES; 
}); 
} 

....以下のコードで

-1

、代わりに5.0あなたはあなたの時間を置くことができる二

[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(targetMethod) userInfo:nil repeats:NO]; 

-(void)targetMethod { 
    //enter code here to execute... 
} 
表示したいメッセージの種類
+0

提案ありがとう –

関連する問題