how to send data from one ViewController to another which has SWRevealViewController

回眸只為那壹抹淺笑 提交于 2019-12-25 07:59:14

问题


I have impleented SWRevealViewController for sideMenu. My project is is Swift and SWRevealViewController is in Objective-c. SWRevealViewController is not initial view Controller.there is one intial View Contoller(1VC) and it has Push segue on SWRevealViewController. another ViewController (2VC) is act as FrontView. I want to pass data from (1VC) to (2VC). but I could not find any way


回答1:


Two ways:

In case of 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)))
 }
}

Otherwise in swift everything is public by default. Define variables outside the class

import UIKit

var placesArray: NSMutableArray!

class FirstViewController: UIViewController {
//
..
//
}

and then access it

import UIKit

class SecondViewController: UIViewController {
//
placesArray = [1, 2, 3]
//

}



来源:https://stackoverflow.com/questions/37782810/how-to-send-data-from-one-viewcontroller-to-another-which-has-swrevealviewcontro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!