I am having trouble programmatically removing stacks from a view. I am doing things a bit convoluted, which is certainly not helping matters. Here is what I want to do:
- User is in one tab of a tab view controller.
- User selects item from table that contains URL.
- App switches to another tab view, and sets an existing UIWebView to the selected URL.
- Any views that are on the UIWebView's stack are popped off, showing the UIWebView.
I have up to step three working fine. But, can not seem to pop any views off the stack. Here is my attempt:
- (void)openAndDisplayURL:(NSString*)URL {
tabBarController.selectedIndex = 0;
UIViewController *selectedController = tabBarController.selectedViewController;
if ([selectedController isKindOfClass:[UINavigationController class]]) {
UINavigationController *controller = (UINavigationController*)selectedController;
NSArray *views = controller.viewControllers;
for (id view in views) {
if([view respondsToSelector:@selector(openURLWithString:)]) {
NSString *completeURL = [NSString stringWithFormat:@"http://%@",URL];
[view openURLWithString:completeURL];
} else if ([selectedController isKindOfClass:[UINavigationController class]]) {
UINavigationController *subcontroller = (UINavigationController*)selectedController;
[subcontroller.navigationController popViewControllerAnimated:NO];
}
}
}
}
Debugging shows the expected number of views, of the type expected. It properly enters the else
block when it's a view that needs to be removed, but calling popViewControllerAnimated:
does nothing.
Any help would be appreciated.