I have a view controller with two collection views and two view controllers in a view that is inside of a scrollview in order to see other views that I haven't added yet. I had all these objects outside of a scrollview and when I added a scroll view and inserted the objects I get a the code:
Thread 1: "*** -[__NSArrayM objectAtIndexedSubscript:]: index 1 beyond bounds [0 .. 0]"
when I launch the app. I am able to run the app and when the launch screen is done loading, it crashes.
Here is the code:
import UIKit
class HomeViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
@IBOutlet weak var t10MacInfCollectionView: UICollectionView!
@IBOutlet weak var t10MicroInfCollectionView: UICollectionView!
let T10Mac = "T10Mac"
let T10Mic = "T10Mic"
override func viewDidLoad() {
super.viewDidLoad()
t10MacInfCollectionView.reloadData()
t10MicroInfCollectionView.reloadData()
t10MacInfCollectionView.delegate = self
t10MicroInfCollectionView.delegate = self
t10MacInfCollectionView.dataSource = self
t10MicroInfCollectionView.dataSource = self
self.view.addSubview(t10MacInfCollectionView)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if collectionView == self.t10MacInfCollectionView {
return 10
}
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.t10MacInfCollectionView {
let cellA = collectionView.dequeueReusableCell(withReuseIdentifier: T10Mac , for: indexPath) as! T10MacroCollectionViewCell
return cellA
}
else {
let cellB = collectionView.dequeueReusableCell(withReuseIdentifier: T10Mic , for: indexPath) as! T10MicroCollectionViewCell
return cellB
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if collectionView == self.t10MacInfCollectionView {
let cellA = collectionView.dequeueReusableCell(withReuseIdentifier: T10Mac, for: indexPath)
return CGSize(width: 125.0, height: 225.0)
}
else {
let cellB = collectionView.dequeueReusableCell(withReuseIdentifier: T10Mic, for: indexPath)
return CGSize(width: 125.0, height: 225.0)
}
}
}
If there is some other code that you guys need to see please let me know. I don't understand why I am getting this error.
Edit: Here is what my exception breakpoint is saying:
[CollectionView] An attempt to update layout information was detected while already in the process of computing the layout (i.e. reentrant call). This will result in unexpected behaviour or a crash. This may happen if a layout pass is triggered while calling out to a delegate. UICollectionViewFlowLayout instance is (<UICollectionViewFlowLayout: 0x7f986fc357c0>)