I have been writing some demos to check the runtime logic, and I by accident found this drawback. I could not discover a solution on main boards, nor did I get a outcome from asking AI, so I am right here to hunt assist.
// The binding logic of the button
(void)jumpToSecondViewController {
NSLog(@"content material of the navigation stack (earlier than):%@",self.navigationController.viewControllers);
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.receivedMessage = @"Hiya World";
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is an alert." preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* defaultAction1 = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction action) {
//[self.navigationController pushViewController:secondVC animated:YES];
NSLog(@"okay");
}];
UIAlertAction defaultAction2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"no");
}];
[alert addAction:defaultAction1];
[alert addAction:defaultAction2];
[self presentViewController:alert animated:NO completion:nil];
[self.navigationController pushViewController:secondVC animated:NO];
NSLog(@"content material of the navigation stack (after):%@", self.navigationController.viewControllers);
NSLog(@"right here");
}
The logic for the push navigation was initially certain to the UIAlertAction
, however I do not perceive why, when positioned in my present place, this system runs usually (it might print “right here”), but the push operation of the navigationController
would not work.
But when I push the ViewController
earlier than presenting the ViewController
, it would work:
// The binding logic of the button
(void)jumpToSecondViewController {
NSLog(@"content material of the navigation stack (earlier than):%@", self.navigationController.viewControllers);
SecondViewController *secondVC = [[SecondViewController alloc] init];
secondVC.receivedMessage = @"Hiya World";
[self.navigationController pushViewController:secondVC animated:NO];
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is an alert." preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* defaultAction1 = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction action) {
//[self.navigationController pushViewController:secondVC animated:YES];
NSLog(@"okay");
}];
UIAlertAction defaultAction2 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"no");
}];
[alert addAction:defaultAction1];
[alert addAction:defaultAction2];
[self presentViewController:alert animated:NO completion:nil];
//[self.navigationController pushViewController:secondVC animated:NO];
NSLog(@"content material of the navigation stack (after):%@",self.navigationController.viewControllers);
NSLog(@"right here");
}
After pushing first, the offered alert will seem usually.
// The binding logic of the button
(void)jumpToSecondViewController {
NSLog(@"content material of the navigation stack (earlier than):%@",self.navigationController.viewControllers);
/// ......
NSLog(@"content material of the navigation stack (after):%@",self.navigationController.viewControllers);
NSLog(@"right here");
}
I printed the stack data within the navigationController
earlier than and after the operation, and located that when presenting first after which pushing, the pushed content material isn’t efficiently added to the stack. I am not fairly positive which space of information I have to find out about, or what inside logic is inflicting this.