簡體   English   中英

pushViewController不能與TabbarController一起使用

[英]pushViewController does not work with TabbarController

我有一個使用故事板的標簽欄控制器應用程序。 每個選項卡都有一個UIWebview。 我想在用戶單擊Webview上的鏈接時捕獲鏈接,如果鏈接是外部鏈接(如果它不是我的站點)我想在不同的UIViewControl中打開鏈接。 (就像一個popupi Twitter iphone應用程序那樣做)

馬上; 我有這個代碼捕獲鏈接(如果鏈接是bing.com然后它應該打開它另一個視圖控制器)但我無法打開另一個UIViewController(在這種情況下PopViewController)。 它給了我這個錯誤:

'GundemViewController'沒有可見的@interface聲明選擇器'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;
}

您可以在每個選項卡中嵌入導航控制器,以便代替:

UITabBarController
    Tab1 View Controller
    Tab2 View Controller
    Tab3 View Controller

你有

UITabBarController
    Tab1 Navigation Controller
        Tab1 View Controller
    Tab2 Navigation Controller
        Tab2 View Controller
    Tab3 Navigation Controller
        Tab3 View Controller

等等。 您只能在導航控制器的實例上調用-pushViewController:animated: .

在您的應用程序委托中,您可能初始化每個視圖控制器,將它們放在一個數組中,然后將該數組分配給選項卡欄控制器。 要添加導航控制器,您還需要一個額外的步驟:

UIViewController *tab1Controller = [[MyViewController alloc] initWithNibNamed:@"MyViewController" bundle:nil];
UINavigationController *tab1Nav = [[UINavigationController alloc] initWithRootViewController:tab1Controller];

// etc

然后將標簽欄控制器的視圖控制器數組設置為您創建的導航控制器。

在你的視圖控制器中,而不是調用-pushViewController:animated: on self ,你將在self.navigationController上調用它。

編輯:

如果您不想使用導航控制器,則可以使用

[self presentViewController:popUpView 
                   animated:YES 
                 completion:nil];

提出彈出窗口。 在彈出窗口中,當用戶觸摸關閉按鈕時,使用

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

解雇它。

什么是GundemViewController 看看為什么從self.navigationController而不是UINavigationController返回。 一種方法是在推動視圖控制器之前設置斷點,然后進入self.navigationController調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM