簡體   English   中英

如何在另一個視圖控制器上設置一個布爾標志?

[英]How do I set a boolean flag on a different view Controller from another?

我有以下代碼:

override func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool {

    var segue = UIStoryboardSegue()
    let viewController = ViewController()
    viewController.check == true
    let photo1 = photos[indexPath.row]
    viewController.photo = photo1
    performSegueWithIdentifier("showDetail", sender: self)
    return true
}

我只希望某些代碼在選擇一個項目后執行。 所以我的計划是創建一個檢查標志。 這里的問題是,當我到達下一個視圖控制器時,標志viewController.check == true永遠不會設置為true。 我已經用println()和東西測試了它,根本沒有設置。 我究竟做錯了什么? 我還應該怎么做?

您的代碼不起作用,因為performSegueWithIdentifier方法實例化了視圖控制器的新實例。 prepareForSegue:sender:方法中,將標志設置為segue.destinationViewController

segue.destinationViewController.check = true 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM