2016-07-05 49 views
0

所以我有2個VC的。在發送VC時,我想將數據發送到接收VC。在製作UIButton時,我在其他項目中通過PrepareForSegue完成了這項工作。這工作完美。 但是現在我創建了一個函數,當條件滿足時它將跳轉到VC。功能如下:PrepareForSegue不起作用的功能,將跳轉到不同的視圖控制器

let vc = self.storyboard?.instantiateViewControllerWithIdentifier("Resultsviewcontroller") as! Resultsviewcontroller 
let navigationController = UINavigationController(rootViewController: vc) 
self.presentViewController(navigationController, animated: false, completion: nil) 

它會跳轉到VC,但與我在PrepareForSegue函數聲明的數據。如何使用PrepareForSegue等函數發送數據?

另外,當跳到接收VC時,它在頂部有一條白線。看起來狀態欄應該在那裏,但在兩個VC中,我將其設置爲「無」。我怎樣才能刪除那條白線?

回答

0

在你的情況下,你不再使用segue展示控制器,並調用presentViewController,你可以做的是如果你的segue存在於你的兩個控制器之間的segue標識符中,你可以稱它爲以編程方式使用performSegueWithIdentifier函數。

如果不存在,您可以手動設置segue並使用函數performSegueWithIdentifier啓動它。你可以從這個答案中受益 How do I create a segue that can be called from a button that is created programmatically?

我希望這對你有所幫助。

+0

不錯,你幫我了。這是答案:dispatch_async(dispatch_get_main_queue()){ [無主自我]在 self.performSegueWithIdentifier(「Test」,sender:self) }這實際上解決了我的另一個問題! – Nahaku

相關問題