我喜欢Swift,iOS开发。
我在ViewController(用于UIKit)和ViewController(用于Spritekit)之间添加了一个Segue。
我运行iPhone模拟器,但内存导航器每个开关ViewController增加30M。
OSX 10.9.5,Xcode.6.1.1
将箭头设置为FirstViewController
选择FirstViewController,选项并拖动GameViewController(Segue)
代码:
class FirstViewController: UIViewController {
@IBAction func returnMenu(segue: UIStoryboardSegue) {
println("back!")
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
performSegueWithIdentifier("toGame", sender: nil)
}
}
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
scene.viewController = self
skView.presentScene(scene)
}
}
}
class GameScene: SKScene {
var viewController: UIViewController?
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
self.viewController?.performSegueWithIdentifier("back", sender: nil)
}
}
感谢。
答案 0 :(得分:0)
class GameScene: SKScene {
weak var viewController: UIViewController?
}
谢谢大家! 弱参考! 内存泄漏解决了!