2017-03-09 37 views
0

我有一個正確更改視圖的函數,但它沒有將變量傳遞到下一個視圖。我真的不是Swift的專家,我不知道我的代碼中的錯誤在哪裏:更改視圖+以編程方式將變量發送到視圖

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let newViewController = storyBoard.instantiateViewController(withIdentifier: "PaymentVC") as! PaymentViewController 
self.present(newViewController, animated: true, completion: nil) 
    newViewController.num_pal = num_words 
    newViewController.l_origen = l_source 
    newViewController.l_destino = l_target 
    newViewController.espec = espec 
    newViewController.user = user 
    newViewController.pass = pass 
    newViewController.texto = texto 
    newViewController.modificado = modificado 
    newViewController.texto_ant = texto_ant 

非常感謝您的幫助。

回答

2

self.present(newViewController, animated: true, completion: nil)應該是傳遞數據後,只是把它所有的newViewController.texto_ant = texto_ant

+0

大多汁後!非常感謝,在11分鐘內我會接受你的回答 – alberzyzz

+0

順便說一下,你知道爲什麼我的導航控制器在做完這個功能後就消失了嗎?我嘗試過:'viewDidLoad()'中的'self.navigationController?.setNavigationBarHidden(false,animated:false)'以及更多,但似乎沒有任何工作... – alberzyzz

+1

你應該調用'self.navigationController?.pushViewController'然後,目前顯示新的'UIViewController'不在導航堆棧中。 @alberzyzz – JuicyFruit

相關問題