In my iOS App, i present a UItableViewController using
...
[self presentViewController:vc animated:YES completion:nil];
...
Now after i tap a row in my tableview, i want to dismiss my tableviewcontroller:
#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self dismissViewControllerAnimated:true completion:^(void) {
NSLog(@"dismissed");
}];
}
Now my problem: dismissViewControllerAnimated works as intended, but I have to tap the row 2 times. The first time i tap the row nothing happens.
Observations so far:
Seems like the completion block will be "scheduled" even if I tap only one time. But the dismissing doesn't happen.
Does anyone know what cause this problem?
Thanks to par and ShahiM I got the solution: I had to dismiss on the Main Thread.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSelectorOnMainThread:@selector(dismissAndshowPdf) withObject:nil waitUntilDone:NO];
}
- (void) dismissAndshowPdf {
[self.presentingViewController dismissViewControllerAnimated:true completion:^(void) {
NSLog(@"dismissed");
}];
}
Call deselectRowAtIndexPath before dismissing controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With