0

我有 UITableview

uitableview 包含播放列表音频歌曲,我在单元格中放了一个按钮。

用户单击行音频开始播放

我想要,当用户单击仅行按钮时应该启用,而单元格应该被禁用

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSURL *url = [[NSURL alloc]initFileURLWithPath:soundsPath];

    NSURL *  playurl =[NSURL URLWithString:[passarray objectAtIndex:indexPath.row] relativeToURL:url];

    if (indexPath.row ==1) {

        buybtn.userInteractionEnabled=YES;
        cell.contentView.userInteractionEnabled=YES;
        buybtn.showsTouchWhenHighlighted=YES;
  }
       player = [[AVAudioPlayer alloc] initWithContentsOfURL:playurl error:nil]; 

        [self.player play];
        player.delegate = self;
   cell =[tableView cellForRowAtIndexPath:indexPath];

       cellText = cell.textLabel.text;

    lbl.text=cellText;
     }
4

3 回答 3

0

在方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

为您需要访问的按钮分配一个标签:buybtn.tag = YOUR_TAG

然后在 didselectrow 方法中:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];

    NSLog(@"sunviews  : %@",cell.subviews);
    for (UIView *_view in cell.subviews) {
        if (_view.tag != YOUR_TAG) {
            [_view setUserInteractionEnabled:NO];
        }
    }
}

希望它可以帮助你。

于 2013-05-01T10:52:59.563 回答
0

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

if(indexPath.row == sepicificRowNumber){

buybtn.userInteractionEnabled=YES;

cell.selectionStyle = UITableViewCellSelectionStyleNone;

}

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

if(indexPath.row == sepicificRowNumber){

//Nothing happen on click   

}

}

希望能帮助到你。

于 2013-05-01T11:13:51.933 回答
0

UITableView's didSelectRowAtIndexPath:这可能会有所帮助:在方法中添加这些代码

补充说然后tag_specific button99

for(UIView *subview in cell.subView)
{
   if(![subview isKindOfClass:[UIButton class]) 
   {
      subview.userInteractionEnabled = NO;
   }
   else
   {
      UIButton *btn = (UIButton *)subview;
      if(btn.tag != 99)
        btn.userInteractionEnabled = NO;
   }
}

编辑:Aspecific button来自enabled.other buttons

于 2013-05-01T10:48:53.697 回答