此倒带方法适用于倒带按钮和播放按钮。
-(void)rewind:(id)sender
{
[timer invalidate];
audioPlayer.currentTime = 0;
MainViewController *viewController = [[MainViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
[viewController release];
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
[self pauseLayer:self.view.layer];
}else{
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
[self resumeLayer:self.view.layer];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO;
}
}
}
现在在这种方法中,发送者是倒带按钮,并且在倒带按钮上发生播放/暂停切换,而我想要在播放按钮上切换而不是发送者,这是倒带按钮。所以我试着给出我想要切换的实际按钮的名称,我在我的代码中将该按钮定义为播放按钮,并且我已经在此倒带方法中添加了其操作方法。
这就是如何定义播放按钮
//Add Play Button
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
playButton.frame = CGRectMake(0, 0, 30, 30);
[playButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateNormal];
[playButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];
UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithCustomView:playButton];
这是我在倒带按钮中添加的播放按钮的方法
-(void)playpauseAction:(id)sender
{
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
[audioPlayer pause];
[self pauseTimer];
[self pauseLayer:self.view.layer];
}
else
{
[sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self resumeTimer];
[self resumeLayer:self.view.layer];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO;
}
}
}
现在我遇到的问题是,当我点击倒带按钮切换时,应该在播放按钮上进行切换而不是倒带按钮。
但是为了解决这个问题,我只需在回放方法中用playButton替换发送者,就像这样
[playButton setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
然后我收到红色的警告信息,使用未声明的标识符playButton。
如何判断倒带方法在playButton上切换而不是在倒带按钮上切换。
请帮忙。
感谢。
答案 0 :(得分:2)
您的"未声明的标识符playButton"告诉你,你没有实例变量playButton。
它可能只在您创建它的方法中可见,但您需要将其保存到iVar中才能从其他方法访问它。