2016-10-10 26 views
0

我想要創建一個應用程序,讓用戶點擊導航欄上的V1按鈕。這將會延續到V2,他們可以在V2上按下導航欄上的另一個按鈕,並將它們帶回到底部具有標籤欄控制器的V1。我不想V2上的標籤欄,我不希望V2作爲標籤欄項目。當我嘗試這個時,當我從V2回到V1時,標籤欄在V1上消失。標籤欄控制器在回到另一個視圖時消失

TAB欄控制器 - > TAB欄項目(V1) - > V2(經由在V1導航欄按鈕項) - >回V1(經由V2導航欄按鈕項)

我已經加入[self.navigationController, popViewControllerAnimated:YES];到我的按鈕功能,但它出現了一個錯誤 - 容器文字中的預期表達式。

除了這段代碼,我還沒有在我的應用程序中的任何其他代碼。

我使用的Xcode 8.0和雨燕3.0

+0

你提到你正在使用雨燕3.0,但你已經添加的功能是在OBJ - C的? –

回答

0

我一直試圖找出一個答案天后解決我的問題。您需要將其添加到任何視圖控制器。

@IBAction func unwindToViewController (sender: UIStoryboardSegue){ 

    } 

然後,您可以添加一個從酒吧按鈕項目的segue到視圖控制器上的退出圖標。

You can view an image of the VC scene here.

0

首先創建的UITabBarController子類,如果你想顯示在應用程序啓動標籤欄控制器然後把這些代碼的屬性,然後添加到AppDelegate

var navController: UINavigationController? 
var tabController: MyTabController? 

AppDelegatedidFinishLaunchingWithOptions

self.window = UIWindow(frame: UIScreen.main.bounds) 
let myStoryboard = UIStoryboard(name: "Main", bundle: nil) as UIStoryboard 
self.tabController = myStoryboard.instantiateViewController(withIdentifier: "MyTabController") as? MyTabController 
//self.navController = UINavigationController(rootViewController: self.tabController!) 
//self.window?.rootViewController = self.navController 
self.window?.rootViewController = self.tabController 
self.window?.makeKeyAndVisible() 
return true 

如果你想登錄或SOM後標籤欄上跳ething否則的話,在viewDidLoad

appDelegate = UIApplication.shared.delegate as? AppDelegate 

添加屬性到控制器

var appDelegate: AppDelegate! 

和方法想

func logIntoApp() { 

    appDelegate.tabController = self.storyboard?.instantiateViewController(withIdentifier: "MyTabController") as? MyTabController 
    appDelegate.window?.rootViewController = appDelegate.tabController 
} 
在標籤項的視圖控制器

然後,創建的AppDelegate屬性,並指定代表如上。

和方法應該是這樣的:

@IBAction func showWithTab(_sender: AnyObject) { 

     let DefaultVC = self.storyboard?.instantiateViewController(withIdentifier: "DefaultViewController") as! DefaultViewController 
     self.navigationController?.pushViewController(DefaultVC, animated: true) 
} 

@IBAction func showWithoutTab(_sender: AnyObject) { 

     let DefaultVC = self.storyboard?.instantiateViewController(withIdentifier: "DefaultViewController") as! DefaultViewController 

    // You can create your own animation 
     UIView.transition(from: (appDelegate.tabController?.view)!, to: (appDelegate.navController?.view)!, duration: 0.3, options: UIViewAnimationOptions.curveEaseIn) { (finished) in 

     self.appDelegate.window?.rootViewController = self.appDelegate.navController 
    } 

    // OR you can use like this way 
     UIView.transition(from: self.view, to: DefaultVC.view, duration: 0.3, options: UIViewAnimationOptions.curveEaseIn) { (finished) in 

     self.appDelegate.window?.rootViewController = self.appDelegate.navController 
    } 
} 
0

爲什麼不使用一個簡單的標籤欄? 事情是這樣的:

enter image description here

和VC1:

override func viewWillDisappear(_ animated: Bool) { 
    super.viewWillDisappear(animated) 

    myTab.removeFromSuperview() 
} 
+0

當我回到帶有標籤欄的視圖時,標籤欄已經消失。 –

+0

@D。Murphy查看我的編輯 – Rob

+0

當我使用導航控制器將VC2中的segue設置爲VC2並使用導航控制器中的push segue將VC2中的segue設置爲VC1時,我添加到VC2導航欄上的欄按鈕項目消失了。對不起,如果我的問題沒有意義,但我想要做的是有兩個VC鏈接到標籤欄。然後,在其中一個VC中,我想在導航欄中有一個欄按鈕項,它允許繼續執行另一個沒有實現標籤欄的VC。在這個VC上,我在導航欄中有另一個欄按鈕項,它讓我可以用選項卡返回到我的VC。謝謝。 –

相關問題