开关语句不起作用。使用switch语句更新视图ater计时器失效。在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 2012-02-27 22:12:27
请缩进您的代码,以便阅读。 – Caleb 2012-02-27 22:14:46
您可能会考虑在displayviewsAction中添加一条日志语句以显示“viewControl”设置为的内容。我怀疑这不是你的想法。 – 2012-02-27 22:24:03