gpt4 book ai didi

ios - Collection View /选项卡栏 Controller 崩溃

转载 作者:行者123 更新时间:2023-11-29 11:31:36 25 4
gpt4 key购买 nike

在我的应用程序中,我使用标签栏 Controller 在 View Controller 之间切换,并且在每个 View Controller 上我使用 Collection View 然后转到不同的页面。当我在计算机上运行该应用程序时,一切正常。问题是当我在手机上运行该应用程序时。每当我单击选项卡栏 Controller 中的选项卡,该选项卡转到上面带有 Collection View Controller 的页面时,应用程序就会卡住然后崩溃。我认为我已经将问题缩小到 Collection View Controller ,因为当没有 Collection View Controller 时,我手机上的应用程序不会崩溃。它仅在使用 Collection View Controller 时崩溃。这可能是什么原因造成的?我已经看过,但没有发现任何类似的问题。

这是其中一个 Collection View Controller 的代码:

import UIKit
class HighSchoolController: UIViewController, \UICollectionViewDataSource, UICollectionViewDelegate {

var identities = [String]()

let hsImage: [UIImage] = [
UIImage(named: "dates")!,
UIImage(named: "athletics_icon")!,
UIImage(named: "interm-1")!,
UIImage(named: "lunch_icon")!,
UIImage(named: "pioneerpress")!,
UIImage(named: "PIONEERNEWS")!,
UIImage(named: "clubs_icon")!,
UIImage(named: "contact_icon")!
]

override func viewDidLoad() {
super.viewDidLoad()

identities = ["events", "athletics", "da", "lunch", "pioneer press", "pioneer news", "clubs", "contact"]

//Navigationbar Shadow
self.navigationController?.navigationBar.layer.shadowColor = UIColor.black.cgColor
self.navigationController?.navigationBar.layer.shadowOffset = CGSize(width: 0.0, height: 4.0)
self.navigationController?.navigationBar.layer.shadowRadius = 9.0
self.navigationController?.navigationBar.layer.shadowOpacity = 0.9
self.navigationController?.navigationBar.layer.masksToBounds = false

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return hsImage.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let hsCell = collectionView.dequeueReusableCell(withReuseIdentifier: "hsCell", for: indexPath) as! HighSchoolCell


hsCell.hsImage.image = hsImage[indexPath.item]

hsCell.layer.cornerRadius = (hsCell.layer.frame.height) / 2.0;
hsCell.layer.masksToBounds = true

return hsCell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
}

最佳答案

我通过在我的标签栏 Controller 中这样做来解决这个问题

  • 让 layout1 = UICollectionViewFlowLayout() 让 cv1 =CollectionView1(collectionViewLayout: layout1)

  • 让 layout2 = UICollectionViewFlowLayout()let cv2 = CollectionView1(collectionViewLayout: layout2)

  • 让 layout3 = UICollectionViewFlowLayout()let cv3 = CollectionView1(collectionViewLayout: layout3)

  • 让 layout4 = UICollectionViewFlowLayout()let cv4 = CollectionView1(collectionViewLayout: layout4)

关于ios - Collection View /选项卡栏 Controller 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53012607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com