微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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


[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
//转到显示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];
	}
}
//选中需要显示contact详情的行走的方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
	tb_Contacts *contacts = (tb_Contacts *)[fetchedResultsController objectAtIndexPath:indexPath];
    [self showContact:contacts animated:YES];
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐