Skip to content

Commit 352da5a

Browse files
committed
Merge branch 'Deselect-after-Segue' of https://github.com/funnel20/InAppSettingsKit
2 parents cee679a + 06449f9 commit 352da5a

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,38 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
902902

903903
NSString *segueIdentifier = specifier.segueIdentifier;
904904
if (segueIdentifier) {
905-
@try {
906-
[self performSegueWithIdentifier:segueIdentifier sender:self];
907-
} @catch (NSException *exception) {
908-
NSLog(@"segue with identifier '%@' not defined", segueIdentifier);
909-
[tableView deselectRowAtIndexPath:indexPath animated:YES];
910-
}
911-
[tableView endUpdates];
905+
@try {
906+
[self performSegueWithIdentifier:segueIdentifier
907+
sender:self];
908+
909+
/*
910+
NOTE: The segue's viewcontroller will be presented modally. Hence any delegate methods on this class, like `viewWillDisappear:` and `viewWillAppear:`, will not be called when that viewcontroller is presented and dismissed. Consequently the selected row is not deselected, since that will be handled in `viewWillAppear:`.
911+
To resolve this, a repeating timer is used to check whether the presented view controller gets dismissed.
912+
*/
913+
NSTimer *checkSegueDismissedTimer = [NSTimer timerWithTimeInterval:0.1
914+
repeats:YES
915+
block:^(NSTimer * _Nonnull timer) {
916+
// When the presented view controller is dismissed:
917+
if (self.presentedViewController == nil) {
918+
// Deselect row:
919+
[self.tableView deselectRowAtIndexPath:indexPath
920+
animated:YES];
921+
922+
// Stop timer:
923+
if ([timer isValid]) {
924+
[timer invalidate];
925+
}
926+
}
927+
}];
928+
929+
// Add timer to the Main runloop:
930+
[[NSRunLoop mainRunLoop] addTimer:checkSegueDismissedTimer
931+
forMode:NSRunLoopCommonModes];
932+
} @catch (NSException *exception) {
933+
NSLog(@"segue with identifier '%@' not defined", segueIdentifier);
934+
[tableView deselectRowAtIndexPath:indexPath animated:YES];
935+
}
936+
[tableView endUpdates];
912937
return;
913938
}
914939

0 commit comments

Comments
 (0)