简体   繁体   English

导航collectionview时导航栏损坏

[英]Corrupted navigation bar when navigating a collectionview

I'm building a tab bar application that consists of 4 tabs. 我正在构建一个包含4个选项卡的选项卡栏应用程序。 Each tab is a collectionviewcontroller embedded in a navigation controller. 每个选项卡都是嵌入在导航控制器中的collectionviewcontroller。 I am encountering an issue with the first view controller that loads. 我正在加载的第一个视图控制器遇到问题。

The first view controller is a subclass of uicollectionviewcontroller, as stated above. 如上所述,第一个视图控制器是uicollectionviewcontroller的子类。 The collection consists of different types of cells. 该集合由不同类型的单元格组成。 When each cell is selected, I perform a segue to a new view controller containing the details of that cell. 选中每个单元格后,我将对包含该单元格详细信息的新视图控制器执行搜索。 When I tap into a cell, and then swipe right to go back, I get the following error: 当我轻按一个单元格,然后向右轻扫以返回时,出现以下错误:

nested push animation can result in corrupted navigation bar

There are many topics on this site regarding this specific error message. 此站点上有许多与此特定错误消息有关的主题。 I've read them all and still can't solve this. 我已经阅读了所有内容,但仍然无法解决。 My error is particularly strange for a few reasons: 由于以下几个原因,我的错误特别奇怪:

  • It only happens when I swipe back (rather than pressing the back button in the navigation controller) 仅当我向后滑动时才发生(而不是按导航控制器中的“后退”按钮)
  • It only happens when I haven't gone to any other tabs in the application. 仅当我没有转到应用程序中的任何其他选项卡时,它才会发生。 If I open the application, go to another tab, and then go back to the default tab, the navigation works perfectly. 如果我打开该应用程序,请转到另一个选项卡,然后返回到默认选项卡,导航将正常工作。

For reference, here is some of my relevant code (sorry it's messy): 供参考,这是我的一些相关代码(对不起,这很混乱):

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    var segueId: String?
    switch self.cards[indexPath.item].type {
        case "standard", "text":
            segueId = "showCard"
            break
        case "question":
            segueId = "showQuestion"
            break
        default:
            segueId = nil
            break
    }
    if let sequeId = segueId {
        self.performSegueWithIdentifier(segueId!, sender: self)
    }
}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "showCard" {
        let indexPaths = collectionView!.indexPathsForSelectedItems()
        let indexPath = indexPaths![0] as NSIndexPath
        let vc = segue.destinationViewController as! CardDetailViewController
        let selectedCard = self.cards[indexPath.item]
        vc.cardTitle = selectedCard.headline
        vc.cardImage = selectedCard.image
        vc.files = selectedCard.files
        vc.cardBody = selectedCard.text

        // set imageview dimensions
        let screenSize: CGRect = UIScreen.mainScreen().bounds
        let screenWidth = screenSize.width
        let boundingRect = CGRect(x: 0, y: 0, width: screenWidth, height: CGFloat(MAXFLOAT))
        if selectedCard.image != nil {
            let rect = AVMakeRectWithAspectRatioInsideRect(selectedCard.image!.size, boundingRect)
            vc.heightOfImage = rect.height
        } else {
            vc.heightOfImage = 0
        }
    }

    if segue.identifier == "showQuestion" {
        let indexPaths = collectionView!.indexPathsForSelectedItems()
        let indexPath = indexPaths![0] as NSIndexPath
        let vc = segue.destinationViewController as! QuestionAnswerViewController
        let selectedCard = self.cards[indexPath.item]
        vc.questionText = selectedCard.headline
        vc.smartEvent = selectedCard.event
        vc.smartLocation = selectedCard.smartLocation
        vc.cardId = selectedCard.cardID
    }

}

Thanks in advance for any help. 在此先感谢您的帮助。

I figured it out. 我想到了。 I had overridden viewDidAppear in the tab bar controller, without calling super.viewDidAppear(). 我在选项卡栏控制器中覆盖了viewDidAppear,而没有调用super.viewDidAppear()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM