2017-08-29 29 views
-3

嗨,我需要幫助在Xcode中使用多.swift文件不同的視圖控制器與SWIFT 3.斯威夫特3採用多.swift文件

例子來說明我的情況,我有:

  • 的ViewController .swift
  • ViewController2.swift
  • 以我故事板2視圖:視圖控制器A,查看控制器B

我如何能顯示或使用視圖控制器B

ViewController.swift交換機的視圖控制器A和ViewController2.swift用於查看控制器B

THX的答案在視圖控制器等隱藏標籤。

回答

-1

您可以在ViewControllerA中有一個static變量,用於決定是否顯示標籤。

ViewControllerA

static var showLabel = false 

func viewDidAppear(_ animated: Bool) { 
    label.hidden = !showLabel 
} 

ViewControllerB

ViewControllerA.showLabel = true 
+0

你能更清楚的是我必須做的PLZ我不untersdant以及 –

+0

@ValentinCocq基本上只是複製代碼解釋我。第一個到你的'ViewControllerA'中。第二個代碼是你想要從哪裏改變狀態。如果你還不明白,我應該在哪裏更清楚? :) – ntoonio

+0

好的thx,我會嘗試。 PS:ViewControllerA is storyboard not .swift –

0

你可以嘗試做一個VAR檢查開關的狀態,然後使用prepareforsegue函數傳遞過來的變種。 然後使用if語句來檢查。

if switchcondition == true { 

    lbl.isHidden == true  

} else if switchcondition == false { 

    lbl.isHidden == false 

} 

其中switchCondition是您的var & lbl是您的標籤插座。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
if segue.identifier == "segue" { 
     var switchCondition = false 
     //I'll keep it false by default 
    } 
} 

不要忘記這一點:

self.performSegue(withIdentifier: "segue", sender: self) 
+0

可以解釋更多顯然plz? –

+0

你能詳細告訴我你不明白的東西嗎? – ItzAmmar