我有一个动态桌面视图,其中有一个按钮,当按下时播放歌曲的原型单元格。更改在UITableview中按下的特定按钮的图像
我想要按钮上的背景图像,当用户按下按钮播放歌曲时变为“停止”图标,并且当用户按下它时变为“播放”图标再一次阻止这首歌。
要做到这一点,我一直在试图使用方法: [self.beatPlayButton setBackgroundImage:[UIImageimageNamed:@"play.png"]forState:UIControlStateNormal];
我的问题是,我还没有想出如何,因为我使用的原型,被按下的行中仅更改按钮细胞。我一直希望找到像didSelectObjectAtRow:atIndexPath:
这样的方法,因为didSelectRowAtIndexPath:
会在按下该行时触发,但不会触发按钮(除非我错了)。也许我应该使用标签?我不确定。任何指针将不胜感激。我的代码不在didSelectRowAtIndexPath
之内。
下面是示例代码 -
- (IBAction)playStopBeat:(UIButton*)sender event:(id)event {
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if([self.audioPlayer isPlaying])
{
[self.beatPlayButton setBackgroundImage:[UIImage imageNamed:@"play.png"]forState:UIControlStateNormal];
[self.audioPlayer stop];
self.isPlaying = NO;
self.audioPlayer = nil;
}
else {
if (indexPath.row == 0) {
[self.beatPlayButton setImage:[UIImage imageNamed:@"stop.png"] forState: UIControlStateNormal];
}
else if (indexPath.row == 1){
[self.beatPlayButton setBackgroundImage:[UIImage imageNamed:@"stop.png"]forState:UIControlStateNormal];
}
else if (indexPath.row == 2){
...
//code to play song
是在'didSelectRowAtIndexPath'中发生的操作还是在按钮发送的某些操作中? –
你能提供一些代码吗?什么动作与按钮相关联? – sergio
我已更新我的问题以提供更多上下文。谢谢。 –