如何将数据从一个 ViewController 发送到另一个具有 SWRevealViewController 的数据
how to send data from one ViewController to another which has SWRevealViewController
我已经为 sideMenu 实现了 SWRevealViewController。我的项目是 Swift,SWRevealViewController 在 Objective-c。 SWRevealViewController 不是初始视图 Controller.there 是一个初始视图控制器 (1VC),它在 SWRevealViewController 上有 Push segue。另一个 ViewController (2VC) 作为 FrontView。我想将数据从 (1VC) 传递到 (2VC)。但我找不到任何方法
两种方式:
万一出现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 中默认为 public。在 class
之外定义变量
import UIKit
var placesArray: NSMutableArray!
class FirstViewController: UIViewController {
//
..
//
}
然后访问它
import UIKit
class SecondViewController: UIViewController {
//
placesArray = [1, 2, 3]
//
}
我已经为 sideMenu 实现了 SWRevealViewController。我的项目是 Swift,SWRevealViewController 在 Objective-c。 SWRevealViewController 不是初始视图 Controller.there 是一个初始视图控制器 (1VC),它在 SWRevealViewController 上有 Push segue。另一个 ViewController (2VC) 作为 FrontView。我想将数据从 (1VC) 传递到 (2VC)。但我找不到任何方法
两种方式:
万一出现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 中默认为 public。在 class
之外定义变量import UIKit
var placesArray: NSMutableArray!
class FirstViewController: UIViewController {
//
..
//
}
然后访问它
import UIKit
class SecondViewController: UIViewController {
//
placesArray = [1, 2, 3]
//
}