2013-02-20 41 views
0

我创造 1)customcell和有1个按钮,滑块1在细胞内。错误: - - [的UIButton的setValue:]:无法识别选择在表发送到实例

  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)按钮i具有取cell.and的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)它的工作原理perfectly.But当我滚动表视图或在一段时间内的应用程序来坠毁,给下面的错误: -

-[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:]:无法识别的选择发送到实例

请帮我

回答

-1

你可能在做- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath的第一部分,如果是这样,您正在创建每次UITableView需要渲染单元时间新UIButtonsUISliders ...

您应该UIButtonUISlider和检查添加属性如果它们被初始化或不...

编辑:

好吧,如果你在你的自定义的UITableViewCell定义Btn_musicprogress的属性,你应该合成米,然后初始化它们是这样的:

// If the Button is not yet initialized, then do it 
if(obj_TextMusicCell.Btn_music == nil) 
{ 
    // Here you should do the initialization code that only have to be done the first time 
    obj_TextMusicCell.Btn_music=[[UIButton alloc] initWithFrame:CGRectMake(130,180, 50,50)]; 
    obj_TextMusicCell.Btn_music.tag = indexPath.row; 
    [obj_TextMusicCell.contentView addSubview:Btn_music]; 
} 

// Now it already exists, just update it... 
if(indexPath.row==play_tg) 
{ 
    [obj_TextMusicCell.Btn_music setImage:[UIImage imageNamed:@"pausemusic.png"] forState:UIControlStateNormal]; 
} 
else 
{ 
    [obj_TextMusicCell.Btn_music setImage:[UIImage imageNamed:@"playmusic.png"] forState:UIControlStateNormal]; 
} 

按照与UISlider同样的想法和你有它...

+0

都喜欢我的UIButton * Btn_music = [[的UIButton的alloc] initWithFrame:方法CGRectMake(130180,50,50)];和用于滑块: - UISlider *进展= [[UISlider的alloc] initWithFrame:方法CGRectMake(180,195,320,10)]; 是不够的?请指导me..Thanks的答案。 – 2013-02-21 03:57:04

+0

现在宣布Btn_music在.h文件中这将如何帮助我解决issue.how,没关系吧,我宣布在.h文件中或.m文件按钮检查它... – apascual 2013-02-21 08:39:16

+0

apascua感谢Reply.But – 2013-02-21 10:11:27

0

您正在使用相同的标记值的UIButton * btn_music以及UISlider *进步,因此UISlider *的进展开始的UIButton实例 使用不同的标签值如果使用1〜200标记值的UIButton然后用201个加上值UISlider *进展

相关问题