【问题标题】:UITableViewCell Accessory taped dont workUITableViewCell 附件录音不工作
【发布时间】:2013-12-29 21:13:40
【问题描述】:

我有自定义 UITableViewCell 和此代码来创建配件

    UIImage *indicatorImage  = [UIImage imageNamed:@"Map.png"];

    UIButton *button = [[UIButton alloc] init];
    [button setImage:indicatorImage forState:UIControlStateNormal];
    [button setFrame:CGRectMake(0, 0, 64, 64)];
    cell.accessoryView = button;

我有这两种方法:

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath        *)indexPath
   {
//[self performSegueWithIdentifier:@"goToDetail" sender:self];
NSLog(@"row");
    }


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

//[self performSegueWithIdentifier:@"goToMap" sender:self];
NSLog(@"accessory");
   }

我想捕获两个不同的事件:一个用于行,一个用于附件,使用我上面提到的两种方法,我只能获取行的事件。如何获得配件?

请帮忙

【问题讨论】:

  • 它应该类似于为按钮指定目标的方式。您只需将目标添加到按钮即可使其工作。
  • 我找到了这个解决方案...
  • 我将此行添加到我的按钮:[button addTarget:self action:@selector(methodTouchDown:) forControlEvents:UIControlEventTouchDown];
  • 然后我使用这个方法:-(void)methodTouchDown:(id)sender

标签: ios uitableview


【解决方案1】:

在每一行中,我都添加了这个我设置为附件的按钮:

 UIButton *button = [[UIButton alloc] init];
    [button setImage:indicatorImage forState:UIControlStateNormal];
    [button setFrame:CGRectMake(0, 0, 64, 64)];
    [button addTarget:self action:@selector(methodTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    button.tag = indexPath.row;
    cell.accessoryView = button;

现在我创建了这个方法

   -(void)methodTouchUpInside:(id)sender

每次我们连续点击一个按钮时,他称之为 meted。要选择调用他的按钮,我们可以使用 button.tag!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多