导航集合视图时导航栏损坏

时间:2015-12-08 21:48:06

标签: ios iphone swift

我正在构建一个包含4个标签的标签栏应用程序。每个选项卡都是嵌入在导航控制器中的collectionviewcontroller。我遇到了第一个加载的视图控制器的问题。

第一个视图控制器是uicollectionviewcontroller的子类,如上所述。该集合由不同类型的细胞组成。当选择每个单元格时,我对包含该单元格细节的新视图控制器执行segue。当我点击一个单元格,然后向右滑动返回时,我收到以下错误:

nested push animation can result in corrupted navigation bar

此网站上有许多关于此特定错误消息的主题。我已经阅读了所有内容但仍无法解决此问题。由于以下几个原因,我的错误特别奇怪:

  • 只有当我向后滑动(而不是按下导航控制器中的后退按钮)时才会发生这种情况。
  • 只有当我没有进入应用程序中的任何其他选项卡时才会发生这种情况。如果我打开应用程序,请转到另一个选项卡,然后返回默认选项卡,导航工作正常。

供参考,以下是我的一些相关代码(对不起它很乱):

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
    }

}

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我明白了。我在标签栏控制器中覆盖了viewDidAppear,而没有调用super.viewDidAppear()。