陈斌彬的技术博客

Stay foolish,stay hungry

tableView的accessoryView的事件

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier] autorelease];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd ];
    button. backgroundColor = [UIColor clearColor]; 
     [button addTarget:self action:@selector(btnClicked: event:) forControlEvents:UIControlEventTouchUpInside ];
    cell.accessoryView = button;
    return cell;
}

- (void)btnClicked:(id)sender event:(id)event
{
   NSSet *touches = [event allTouches];
   UITouch *touch = [touches anyObject];
   CGPoint currentTouchPosition = [touch locationInView:tableView];
   NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:currentTouchPosition];
   if (indexPath != nil)
   {
         [self tableView:selectedItemsTableView accessoryButtonTappedForRowWithIndexPath : indexPath];
   }
}

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