3

テーブルビューに 2 つのセクションと 2 つの行を挿入した後、 を使用して選択したセクションと行の値を取得しようとしましたがUITapGestureRecognizer、値のみを取得する必要がindexPath.sectionあり、セクションと行の値の両方が必要です。それは可能ですか?私を助けてください

前もって感謝します

私はこれを試しました:

- (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
}
4

2 に答える 2

3

このコードを使用してください..

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:
[[sender superview] tag]];
于 2013-08-03T08:26:47.507 に答える