Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7190

Error: Thread 1: "*** -[__NSArrayM objectAtIndexedSubscript:]: index 1 beyond bounds [0 .. 0]"

$
0
0

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 beyondbounds [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 UIKitclass 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 an image of the exception for the breakpoint on the line that crashes:

enter image description here


Viewing all articles
Browse latest Browse all 7190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>