Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView didSelectRowatIndexPath not called on single tap

Very very strange! It works everywhere but here:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
 MyViewController* cliente = [[MyViewController alloc] initWithModeAndClientId:2 c:cid];

            cliente.delegate                    = self;
            UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:cliente];

            n.navigationBarHidden     = NO;
            [[n navigationBar] setBarStyle:UIBarStyleBlack];
            [self presentViewController:n animated:YES completion:nil];
}

If I tap by a single click on the row, the MyViewController shows after seconds! If I click twice, it shows rapidly! In the Profiler, at single click nothing happens... I have no didDeselectRowAtIndexPath method.

like image 255
gdm Avatar asked Feb 15 '23 14:02

gdm


2 Answers

The solution is to put on the main thread the loading of the second controller

 dispatch_async(dispatch_get_main_queue(), ^{ 
       // Code here 
 });
like image 121
gdm Avatar answered Feb 23 '23 21:02

gdm


Its issue of threading, when you tap a row in tableview it start a new thread so the presenting a view may take longer to show up on screen.

The solution is:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ 
    dispatch_async(dispatch_get_main_queue(), ^{

        MyViewController* cliente = [[MyViewController alloc] initWithModeAndClientId:2 c:cid];

        cliente.delegate = self;
        UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:cliente];

        n.navigationBarHidden = NO;
        [[n navigationBar] setBarStyle:UIBarStyleBlack];
        [self presentViewController:n animated:YES completion:nil];
    });
}
like image 33
Nirav Limbasiya Avatar answered Feb 23 '23 20:02

Nirav Limbasiya