UITableview - tableView: didDeselectRowAtIndexPath: method not working correctly?

In my application, I am using UITableview. In this delegate method didselectrow, if I did any operation, maybe simple.

For example, I have 3 rows in a tableview

If I select 1 row (indexPath.row == 0), nothing will happen

if you select 2 rows again (indexPath.row == 1), now this is Logging in the console indexPath.row == 0, which is the previous value.

if you select 1 row again and then register its previous value indexPath.row = 1.

Why is this happening.

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{

       CustomerInfoViewController *customer = [[EquipmentViewController alloc]initWithNibName:@"CustomerInfoViewController" bundle:nil];

    EquipmentViewController *equpment = [[EquipmentViewController alloc]initWithNibName:@"EquipmentViewController" bundle:nil];

    ContactsViewController *contacts = [[ContactsViewController alloc]initWithNibName:@"ContactsViewController" bundle:nil];

    if(indexPath.row == 0)
    {

        NSLog(@"one %d",indexPath.row);
        [detailsView addSubview:customer.view];
    }

    if(indexPath.row == 1)
    {

         NSLog(@"two %d",indexPath.row);
        [detailsView addSubview:equpment.view];
    }

    if(indexPath.row == 2)
    {

         NSLog(@"three%d",indexPath.row);
        [detailsView addSubview:contacts.view];
    }
}

Please help me.

Thanks in advance.

+5
source share
2 answers

You implemented the method didDeselectRowAtIndexPath, not didSelectRowAtIndexPathas intended

+19

, . SelectRowAtIndexPath

+1

All Articles