Switch文が機能しません。 switch文を使用してビューを更新すると、aterタイマーが無効になります。 switchステートメントでは、最初のビューから2番目のビューに切り替えることになっていますが、そうしていません。Switch文が機能しない
@property (nonatomic, assign) NSUInteger viewControl;
@synthesize viewControl;
-(void)playpauseAction:(id)sender
{
if
([audioPlayer isPlaying]){
[sender setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[timer invalidate];
} else {
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
self.timer = [NSTimer scheduledTimerWithTimeInterval:11 target:self selector:@selector(displayviewsAction:) userInfo:nil repeats:NO];
}
}
- (void)displayviewsAction:(id)sender
{
switch(viewControl)
{
case 0:
[self performSelector:@selector(FirstViewController) withObject:nil];
break;
case 1:
[self performSelector:@selector(secondViewController) withObject:nil];
break;
case 2:
[self performSelector:@selector(thirdViewController) withObject:nil];
break;
}
}
-(void)FirstViewController {
FirstViewController *viewController = [[FirstViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
[viewController release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(secondViewController) userInfo:nil repeats:NO];
}
-(void)secondViewController {
SecondViewController *secondController = [[SecondViewController alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:secondController.view];
[self.view addSubview:toolbar];
[secondController release];
self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(ThirdviewController) userInfo:nil repeats:NO];
}
コードには何も表示されません。
switch文以外の 'viewControl'への参照はありません。その価値は何で、それはどこから来たのですか? – UIAdam
読みやすいようにコードをインデントしてください。 – Caleb
"viewControl"の設定を表示するには、displayviewsAction内にlogステートメントを追加することを検討してください。私はそれがあなたが思うものではないと思う。 –