3
我已經在tableview中插入2段和2行,然後我嘗試使用UITapGestureRecognizer
獲得選定的段和行值,但我只能得到indexPath.section
的值,我想要段和行的值。有可能這樣做嗎?請幫我如何在UITableView中獲取選定的indexPath.section和indexPath.row值?
由於提前
我嘗試這樣做:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
// Add the PatientName Label
UILabel *cellTitle=[[UILabel alloc]initWithFrame:CGRectMake(100, 7, 300, 30)];
cellTitle.userInteractionEnabled = YES;
cellTitle.tag = indexPath.section;
[cellTitle setBackgroundColor:[UIColor clearColor]];
[cellTitle setFont:[UIFont fontWithName:@"Helvetica" size:14]];
[cellTitle setText:[[cellArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
[cell.contentView addSubview:cellTitle];
UITapGestureRecognizer *labelTap = [[UITapGestureRecognizer alloc] init];
[labelTap addTarget:self action:@selector(viewPatient:)];
[labelTap setDelegate:nil];
[labelTap setNumberOfTapsRequired:1];
[cellTitle addGestureRecognizer:labelTap]; // cellTitle add here
[labelTap release];
}
-(void)viewPatient:(id)sender
{
UITapGestureRecognizer *lSender = sender;
UILabel *lObjLabel = (UILabel *)[lSender view];
NSLog(@"tag:%d",lObjLabel.tag); // only get indexpath.section value
}