【发布时间】:2013-12-03 09:36:19
【问题描述】:
我在 uitableviewcell 中获取值时遇到问题。
首先,我的单元格上有一个标签,我在其上创建了一个点击手势。我想要做的是在点击该标签时,将调用 viewUser 方法,它将获取被点击的单元格的详细信息。
这是我的代码:
在 cellForRowAtIndexPath 上:
cell.userNameLabel.text = [[_workflowList objectAtIndex:indexPath.row] userName];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewUser:)];
tapGestureRecognizer.numberOfTapsRequired = 1;
[cell.userNameLabel addGestureRecognizer:tapGestureRecognizer];
cell.userNameLabel.userInteractionEnabled = YES;
现在,当我调用 viewUser 的 ontap 方法时:
- (IBAction)viewUser:(id)sender {
//this should not be hard coded
//data should come from cell.
//usernamelabel or i will get the index selected
//and get the details in my array
// like this --> [_workflowList objectAtIndex:index]
WorkflowProfileViewController *chkDtl = [[WorkflowProfileViewController alloc]init];
chkDtl.name = @"USER, USER USER"; ;
chkDtl.phoneNo = @"09173210836";
chkDtl.email = @"romelync@sxchange.com";
[self.navigationController pushViewController:chkDtl animated:YES];
}
请帮帮我。
【问题讨论】:
-
你没有。您永远不应该将数据存储在单元格中。您将它存储在一个数组中,然后填充单元格。
-
什么是部署目标?
-
是的,如您所见,我所指的数据是我的数组_workflowList 中的数据。我要说的是如何直接从所选单元格中获取它,或者如何获得所选单元格的索引。我想我已经解释得很好了。
标签: ios uitableview