How to get selected indexPath.section and indexPath.row value in UITableView?
11,182
Use this code..
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:
[[sender superview] tag]];
Comments
-
SampathKumar about 2 years
I have insert 2 section and 2 rows in tableview, then i tried to get selected section and row value using
UITapGestureRecognizer
, but i have to get onlyindexPath.section
value, i want both section and row value. Is it possible to do that? please help meThanks in Advance
I tried this:
- (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 }