I have a Tab Bar Controller app which using storyboard. Each tab has a UIWebview. I want to capture link when the user click the link on Webview if the link is an external link (if it is not my site) I want to open the link in a different UIViewControl. (like a popupi Twitter iphone app do that)
Right now; I got this code for capture the link (if the link is bing.com then it should open it another view controller) but I cannot open another UIViewController (in this case PopViewController). It gives me this error:
No visible @interface for 'GundemViewController' declares the selector 'pushViewController:animated:'
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
//CAPTURE USER LINK-CLICK.
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
/******
UIWebViewNavigationTypeLinkClicked: When user click on a link in the app it senses the action
*/
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if ([urlString hasPrefix:@"http://www.bing.com/"]) {
PopViewController *popUpView = [[PopViewController alloc] initWithNibName:@"PopupViewController" bundle:nil];
[self pushViewController:popUpView animated:YES];
return NO;
}
}
return YES;
}
You can embed navigation controllers in each tab, so that instead of:
UITabBarController
Tab1 View Controller
Tab2 View Controller
Tab3 View Controller
you have
UITabBarController
Tab1 Navigation Controller
Tab1 View Controller
Tab2 Navigation Controller
Tab2 View Controller
Tab3 Navigation Controller
Tab3 View Controller
and so on. You can only call -pushViewController:animated:
on an instance of a navigation controller.
In your app delegate, you probably initialize each of your view controllers, put them in an array, and then assign that array to the tab bar controller. To add navigation controllers, you have an extra step:
UIViewController *tab1Controller = [[MyViewController alloc] initWithNibNamed:@"MyViewController" bundle:nil];
UINavigationController *tab1Nav = [[UINavigationController alloc] initWithRootViewController:tab1Controller];
// etc
Then set the array of view controllers for your tab bar controller to the navigation controllers you've created.
In your view controllers, rather than call -pushViewController:animated:
on self
, you'll call it on self.navigationController
.
edit:
If you don't want a navigation controller, you can use
[self presentViewController:popUpView
animated:YES
completion:nil];
to present the pop up. In the pop up, when the user touches the close button, use
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
to dismiss it.
What is GundemViewController
? Look into why that is being returned from self.navigationController
instead of UINavigationController
. One way to do that is to set a breakpoint just before you push the view controller and then step into the self.navigationController
call.
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