有人可以帮我弄清楚为什么我的UIImageView不在我的视图层次结构中吗?接收视图层次结构警告

时间:2016-06-19 06:39:35

标签: ios swift xcode7

每当第一个开关条件被触发时,UIImageView就会出现,并使用当前图像进行更新......但是当在第二个和第三个开关条件下调用带有标识符或segue的segue时...我得不到图像视图,并且警告:

<小时/>      Warning: Attempt to present <RockPaperScissorsGame.ResultsViewController: 0x7fe67aa1a010> on <RockPaperScissorsGame.ViewController: 0x7fe678c244c0> whose view is not in the window hierarchy! 此外,如果我隐式解开resultsImage!.image,我会得到nil例外。我甚至添加了对controlla.showResults()的调用以确保视图已更新。我确信图像是有效的并且存在。我只是无法弄清楚为什么我没有访问ResultsViewController中的视图层次结构以获取切换条件:2和3.我是一个java转为iOS dev(学生),任何帮助将不胜感激。 (这不是作业)

<小时/> 查看控制器

import UIKit

class ViewController: UIViewController
{
    @IBOutlet weak var rockButtom: UIButton!
    @IBOutlet weak var paperButton: UIButton!
    @IBOutlet weak var scissorsButton: UIButton!
    var controlla : ResultsViewController!
    var firstController : ViewController!
    var str : Int!

    override func viewWillAppear(animated: Bool)
    {
        super.viewWillAppear(true)
        self.controlla =     storyboard?.instantiateViewControllerWithIdentifier("ResultsViewController") as? ResultsViewController
        rockButtom.tag = 1
        paperButton.tag = 2
        scissorsButton.tag = 3
    }

    @IBAction func playGame(sender : UIButton)
    {

        let tag = sender.tag
        let num = arc4random_uniform(2)
        let num2 : Int

        if(num==0)
        {num2=1}
        else{num2=0}
        print("num1: \(num)")
        print(num2)

        switch(tag)
        {
            case 1 :
            controlla!.currentImage = UIImage.init(named: "r1-p\(num)-s\    (num2)")!
            self.presentViewController(self.controlla!, animated: true, completion: nil)
                break
            case 2 :
            self.controlla!.currentImage = UIImage.init(named: "r\(num)-p1-s\(num2)")!
            self.controlla.showResults()
            performSegueWithIdentifier( "transitionTime", sender: paperButton)
                break
            case 3 :
            controlla!.currentImage = UIImage.init(named: "r\(num2)-p\(num)-s1")!
                break

        default:
            break
    }
}

   override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
   {
       if(segue.identifier == "letsPlay")
       {
           print("Prepare for segue has been called!")
       }
   }
}

ResultsViewController     进口基金会     导入UIKit

class ResultsViewController : UIViewController
{
    @IBOutlet var myView: UIView!
    @IBOutlet weak var topBarView: UIView!
    @IBOutlet weak var resultsLabel: UILabel?
    @IBOutlet weak var resultsImage: UIImageView?
    var currentImage: UIImage = UIImage()


    override func viewDidLoad()
    {
        showResults()
    }

    func showResults() -> UIImage
    {  
        resultsImage?.image = currentImage
        return currentImage
    }
}

0 个答案:

没有答案