根据用户在tableview中点击(触摸)cell的自定义accessoryButton获得其indexpath

来源:互联网 发布:smt贴片机编程视频 编辑:程序博客网 时间:2024/05/11 00:26


  1. [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];  
  2. cell.accessoryView = button; 
[java] view plaincopy
  1. <pre name="code" class="java"></pre><pre name="code" class="java">//转到显示contact详情页面  
  2. - (void)showContact:(tb_Contacts *)contacts animated:(BOOL)animated {  
  3.     // Create a detail view controller, set the Contact, then push it.  
  4.     EditContactViewController *editContactViewController = nil;  
  5.     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)   
  6.     {  
  7.         editContactViewController = [[EditContactViewController alloc] initWithNibName:@"EditContactViewController_Ipad" bundle:nil];  
  8.     }  
  9.     else   
  10.     {  
  11.         editContactViewController = [[EditContactViewController alloc] initWithNibName:@"EditContactViewController" bundle:nil];  
  12.     }  
  13.     editContactViewController.contacts = contacts;  
  14.     editContactViewController.managedObjectContext = self.managedObjectContext;  
  15.     editContactViewController.hidesBottomBarWhenPushed=YES;  
  16.     [self.navigationController pushViewController:editContactViewController animated:animated];  
  17.     [editContactViewController release];  
  18. }  
  19. //点击详情按钮后走的方法  
  20. - (void)checkButtonTapped:(id)sender event:(id)event  
  21. {  
  22.     NSSet *touches = [event allTouches];  
  23.     UITouch *touch = [touches anyObject];  
  24.     CGPoint currentTouchPosition = [touch locationInView:self.contactsTableView];  
  25.     NSIndexPath *indexPath = [self.contactsTableView indexPathForRowAtPoint: currentTouchPosition];  
  26.       
  27.     if (indexPath != nil)  
  28.     {  
  29.     [self tableView: self.contactsTableView accessoryButtonTappedForRowWithIndexPath: indexPath];  
  30.     }  
  31. }</pre><pre name="code" class="java">//选中需要显示contact详情的行走的方法  
  32. - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath  
  33. {  
  34.     tb_Contacts *contacts = (tb_Contacts *)[fetchedResultsController objectAtIndexPath:indexPath];  
  35.     [self showContact:contacts animated:YES];  
  36. }

0 0