I've been having trouble trying to add a UICollectionView inside my view Controller. This is the error I'm getting when I try to run my app:
When I run my app Im getting this error: NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] instantiated view controller with identifier "UIViewController-UZJ-6r-Rwt" from storyboard "Main", but didn't get a UICollectionView.' What would be causing this error?
This is the code I have for the View Controller.
import UIKit
class ViewController: UICollectionViewController {
var names = ["a","d","f","f","h","u","p","s","l","g","y","h","l","k","d"]
var images = [UIImage(named: "title205571580"),UIImage(named: "title193064553"),UIImage(named: "title311505831"),UIImage(named: "title351533554"),UIImage(named: "title528311821"),UIImage(named: "title528311821"),UIImage(named: "title543192229"),UIImage(named: "title544380635"),UIImage(named: "title579492173"),UIImage(named: "title673858816"),UIImage(named: "title713937166"),UIImage(named: "title718520594"),UIImage(named: "title743923696"),UIImage(named: "title800939906"), UIImage(named: "title987804505")]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 15
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "uicvcell", for: indexPath) as! UICVCell
let image = cell.viewWithTag(1) as! UIImageView
image.image = images[indexPath.row]
let name = cell.viewWithTag(2) as! UILabel
name.text = names [indexPath.row]
return cell
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if(indexPath.row == Int("0")){
performSegue(withIdentifier: "0", sender: nil)
}
else if(indexPath.row == Int("1")){
performSegue(withIdentifier: "1", sender: nil)
}
else if(indexPath.row == Int("2")){
performSegue(withIdentifier: "2", sender: nil)
}
else if(indexPath.row == Int("3")){
performSegue(withIdentifier: "3", sender: nil)
}
else if(indexPath.row == Int("4")){
performSegue(withIdentifier: "4", sender: nil)
}
else if(indexPath.row == Int("5")){
performSegue(withIdentifier: "5", sender: nil)
}
else if(indexPath.row == Int("6")){
performSegue(withIdentifier: "6", sender: nil)
}
else if(indexPath.row == Int("7")){
performSegue(withIdentifier: "7", sender: nil)
}
else if(indexPath.row == Int("8")){
performSegue(withIdentifier: "8", sender: nil)
}
else if(indexPath.row == Int("9")){
performSegue(withIdentifier: "9", sender: nil)
}
else if(indexPath.row == Int("10")){
performSegue(withIdentifier: "10", sender: nil)
}
else if(indexPath.row == Int("11")){
performSegue(withIdentifier: "11", sender: nil)
}
else if(indexPath.row == Int("12")){
performSegue(withIdentifier: "12", sender: nil)
}
else if(indexPath.row == Int("13")){
performSegue(withIdentifier: "13", sender: nil)
}
else if(indexPath.row == Int("14")){
performSegue(withIdentifier: "14", sender: nil)
}
else if(indexPath.row == Int("15")){
performSegue(withIdentifier: "15", sender: nil)
}
else if(indexPath.row == Int("16")){
performSegue(withIdentifier: "16", sender: nil) }
else if(indexPath.row == Int("17")){
performSegue(withIdentifier: "17", sender: nil)
}
else if(indexPath.row == Int("18")){
performSegue(withIdentifier: "18", sender: nil)
}
}
}