您的位置:首页 > 其它

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

2015-08-18 10:15 465 查看
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;

[java]
view plaincopy

<pre name="code" class="java"></pre><pre name="code" class="java">//转到显示contact详情页面
- (void)showContact:(tb_Contacts *)contacts animated:(BOOL)animated {
// Create a detail view controller, set the Contact, then push it.
EditContactViewController *editContactViewController = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
editContactViewController = [[EditContactViewController alloc] initWithNibName:@"EditContactViewController_Ipad" bundle:nil];
}
else
{
editContactViewController = [[EditContactViewController alloc] initWithNibName:@"EditContactViewController" bundle:nil];
}
editContactViewController.contacts = contacts;
editContactViewController.managedObjectContext = self.managedObjectContext;
editContactViewController.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:editContactViewController animated:animated];
[editContactViewController release];
}
//点击详情按钮后走的方法
- (void)checkButtonTapped:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.contactsTableView];
NSIndexPath *indexPath = [self.contactsTableView indexPathForRowAtPoint: currentTouchPosition];

if (indexPath != nil)
{
[self tableView: self.contactsTableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}</pre><pre name="code" class="java">//选中需要显示contact详情的行走的方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
tb_Contacts *contacts = (tb_Contacts *)[fetchedResultsController objectAtIndexPath:indexPath];
[self showContact:contacts animated:YES];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: