【问题标题】:how to send data from one ViewController to another which has SWRevealViewController如何将数据从一个 ViewController 发送到另一个具有 SWRevealViewController
【发布时间】:2016-10-13 11:05:39
【问题描述】:

我已经为 sideMenu 实现了 SWRevealViewController。我的项目是 Swift 而 SWRevealViewController 在 Objective-c 中。 SWRevealViewController 不是初始视图控制器。有一个初始视图控制器(1VC),它在 SWRevealViewController 上具有 Push segue。另一个 ViewController (2VC) 充当 FrontView。我想将数据从(1VC)传递到(2VC)。但我找不到任何方法

【问题讨论】:

  • 你要发送什么样的数据?
  • 一些字符串从 Intial ViewController(在 SWRevealViewController 之前)到 anotherViewController(这里是 DashBoard,它是 SWRevealViewControllerSegueSetController segue)
  • 在这种情况下,NSNotificationCenter 是完成功能的最佳方式。更多参考请见iosdevcenters.blogspot.com/2016/03/…
  • 在 swift 中,一切都是公开的,因此您可以在类范围之外定义变量,即在 import 语句之后。

标签: ios objective-c swift swrevealviewcontroller objective-c-swift-bridge


【解决方案1】:

两种方式:

如果发生转场

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]
//

}

【讨论】:

  • 快乐是我的
猜你喜欢
  • 1970-01-01
  • 2023-03-31
  • 2018-06-21
  • 2017-11-14
  • 1970-01-01
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多