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

本文介绍了一个iOS应用中展示联系人详情的方法。通过自定义UITableViewCell,加入UIButton并设置点击事件来跳转到联系人详情页面。根据设备类型选择加载iPad或iPhone版本的界面,并通过managedObjectContext传递数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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




                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值