Benim SecondViewController içinde bir Boole firstAppear var. Bir video oynatıldığında Bool yanlış olur. Daha sonra FirstViewController'a geri dönüp geri dönersem, video tekrar oynatılır. Anladığım kadarıyla, her zaman ViewController'ın başka bir örneğini yaratıyorum, bu yüzden mantığımın neden yanlış olduğunu. Bunu başarmak için yapmam gereken değişiklikler nelerdir? firstAppear işe yaramıyor, ViewController init her zaman
@IBAction func nextButtonPressed(sender: AnyObject) {
if let secondViewController = storyboard?.instantiateViewControllerWithIdentifier("answer") as? SecondViewController{
SecondViewController.id = self.id
}
self.navigationController?.pushViewController(secondViewController, animated: true)
}
Ve İkinci içinde
:private var firstAppear = true
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if firstAppear {
do {
try playVideo()
firstAppear = false
} catch AppError.InvalidResource(let name, let type) {
debugPrint("Could not find resource \(name).\(type)")
} catch {
debugPrint("Generic error")
}
}
}
@IBAction func pop(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
}
Tamam, ama aynı ekrandan daha fazla örnek yapmalı mıyım? Bu gitmek için doğru yol mu? – PoolHallJunkie
Genel olarak, 'instantiateViewControllerWithIdentifier' öğesini çağırmamanız gerekir. Storyboard segue kullanmalısınız. Ama bu da çok sayıda örnek oluşturacak. Görünüm denetleyicileri, şu anda ekranda görünmüyorsa, hiçbir zaman varolmaması gerekir. (Segues için bkz. Https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/StoryboardSegue.html.) –