簡體   English   中英

轉到另一個故事板 Swift

[英]Segue to Another Storyboard Swift

我試圖以編程方式轉到另一個故事板,但是每次我嘗試加載視圖時,都會顯示一個沒有內容的黑屏。

這是我一直在使用的代碼:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let startingView = storyboard.instantiateViewControllerWithIdentifier("HomeScreenView")
self.showViewController(startingView, sender: self)

我已經在目標故事板的起源故事板上創建了參考,並且還嘗試調用:

performSegueWithIdentifier("changeover", sender: self)

任何想法和建議將不勝感激。

我在使用帶有 segue 的 Storyboard References 時沒有遇到問題。 以下是我為使其正常工作而遵循的步驟:

1) 在帶有源視圖控制器的情節提要中,將情節提要引用拖到畫布上。

2) 在屬性檢查器中將引用設置為指向正確的故事板名稱和視圖控制器

3) Ctrl+從源的視圖控制器圖標(在場景的頂部欄中)拖動到情節提要參考以創建轉場。

4)將segue設置為“Show”並在屬性檢查器中為其指定標識符“Test”

5) 在源視圖控制器的代碼中,在您希望觸發它的適當位置,添加以下行:

performSegueWithIdentifier("Test", sender: self)

這應該是以編程方式調用 segue 所需的一切!

“MyStoryBoard”這是你想要去的故事板名稱“StoryboardId”這是我想在segue之后顯示的控制器ID。

let storyboard = UIStoryboard(name: "Service", bundle: nil)
    let myVC = storyboard.instantiateViewController(withIdentifier: "ProfileTimelineVC") as! ProfileTimelineVC
    self.present(myVC, animated: true, completion: nil)

在 AppDelegate 中追加 var 窗口:UIWindow?

    let storyboard = UIStoryboard(name: "Registration", bundle: nil)
    let registrationvc = storyboard.instantiateViewController(withIdentifier: 
        "RegistrationViewController") as! RegistrationViewController
    self.window?.rootViewController?.present(registrationvc, animated: true, 
    completion: nil)

暫無
暫無

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

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