我在表格中创建了 1)customcell,单元格内有 1 个按钮和 1 个滑块。
NSString *CellIdentifier = [NSString stringWithFormat:@"%d",indexPath.row];
if (obj_TextCell == nil) {
obj_TextCell = [[[TextCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
UIButton* Btn_music=[[UIButton alloc] initWithFrame:CGRectMake(130,180, 50,50)];
if (indexPath.row==play_tg)
{
[Btn_music setImage:[UIImage imageNamed:@"pausemusic.png"] forState:UIControlStateNormal];
}else
{
[Btn_music setImage:[UIImage imageNamed:@"playmusic.png"] forState:UIControlStateNormal];
}
[Btn_music addTarget:self action:@selector(playAudio:) forControlEvents:UIControlEventTouchUpInside];
Btn_music.tag = indexPath.row;
[obj_TextMusicCell.contentView addSubview:Btn_music];
[background bringSubviewToFront:Btn_music];
UISlider *progress = [[UISlider alloc] initWithFrame:CGRectMake(180,195,320,10)];
[progress setBackgroundColor:[UIColor clearColor]];
progress.minimumValue = 0.0;
progress.maximumValue=1.0;
progress.continuous = YES;
progress.value = 0.0;
progress.tag=indexPath.row+1;
NSLog(@"tag for slider========>%d",progress.tag);
//[progress setTag:indexPath.row];
[progress addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
[obj_TextMusicCell.contentView addSubview:progress];
2)我已经获取单元格的按钮的 IBACTION 事件。并调用了滑块移动的方法。
-(IBAction)playAudio:(id)sender
{
UIButton *Btn_music=sender;
cell_Access = (TextMusicCell *)[tbl_tellTale viewWithTag:0];
NSIndexPath *indexPath = [tbl_tellTale indexPathForCell:cell_Access];
NSLog(@"cellindex==>%d",indexPath.row);
if ( timer==nil)
{
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(SongProgress) userInfo:nil repeats:YES];
[timer fire];
}
}
3)滑块中的方法有:-
-(IBAction)SongProgress
{
UISlider* progress = (UISlider *)[cell_Access viewWithTag:1];
}
4)它工作得很好。但是当我滚动表格视图或有时应用程序崩溃并给出以下错误: -
-[UIButton setValue:]: unrecognized selector sent to instance 0x96f9660
2013-02-20 19:54:21.008 shc[3776:19d03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton setValue:]: unrecognized selector sent to instance 0x96f9660'
*** First throw call stack:
(0x3dba012 0x2777e7e 0x3e454bd 0x3da9bbc 0x3da994e 0x108d1b 0x21c0b90 0x3d79376 0x3d78e06 0x3d60a82 0x3d5ff44 0x3d5fe1b 0x33de7e3 0x33de668 0x16bf65c 0x2cb6 0x2be5 0x1)
libc++abi.dylib: terminate called throwing an exception
-[UIButton setValue:]: 无法识别的选择器发送到实例
请帮我