こんにちは、iPhone アプリでカスタム プログレス バーを表示しようとしています。プログレス バーの値をインクリメントするメソッドを作成しています。値が 100% になったら、タイマーを無効にする必要があり、この再帰を停止する必要があります。次のviewControllerを表示します。私のコードスニペットは以下のようなものです、
-(void)progressNextValue
{
progressValue += 1.0f;
if(progressValue >= progress.maxValue){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"end" message:@"TimeOut!!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
NSLog(@"Time Out!!!!");
[mytimer invalidate];
Second *sec = [[Second alloc] initWithNibName:@"Second" bundle:nil];
[self.view addSubview:sec.view];
}
progress.currentValue = progressValue;
mytimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(progressNextValue) userInfo:nil repeats:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
progress.maxValue = 100.0f;
[self progressNextValue];
}
ここでも、私progressValue = progress.maxValue
のmytimer
が無効化されていません。
どんな助けでも事前に感謝します。