開關語句不起作用。使用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