我已经为sideMenu实现了SWRevealViewController。我的项目是Swift,SWRevealViewController在Objective-c中。 SWRevealViewController不是初始视图Controller.there有一个初始View Contoller(1VC),它在SWRevealViewController上有Push segue。另一个ViewController(2VC)充当FrontView。我想将数据从(1VC)传递到(2VC)。但我找不到任何方式
答案 0 :(得分:0)
两种方式:
如果是segue
override func prepareForSegue(segue: UIStoryboardSegue!,sender: AnyObject!){
//make sure that the segue is going to secondViewController
if segue.destinationViewController is secondViewController{
// now set a var that points to that new viewcontroller so you can call the method correctly
let nextController = (segue.destinationViewController as! secondViewController)
nextController.setResultLabel((String(myResult)))
}
}
否则在swift中默认情况下一切都是公开的。定义类外的变量
import UIKit
var placesArray: NSMutableArray!
class FirstViewController: UIViewController {
//
..
//
}
然后访问它
import UIKit
class SecondViewController: UIViewController {
//
placesArray = [1, 2, 3]
//
}