现在的位置: 首页 > 综合 > 正文

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

2013年12月09日 ⁄ 综合 ⁄ 共 1581字 ⁄ 字号 评论关闭

[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];
}


抱歉!评论已关闭.