Learn Courses My Dashboard


Hi! So im coding and I’m about to lauch the app via the simulator but I’t crashes and I get this error message.

Thread 1: “-[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x130f0a530”

and I can’t seem to find the bug?

Here is the code.

import UIKit

class ViewController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return SliderImages.count
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionCell
        cell.myWebImage.image=UIImage(named: SliderImages[indexPath.row])
        return cell
    @IBOutlet var myPage: UIPageControl!
    var SliderImages:[String]=["3","4","5"]
   // var currentPage:Int=0

    override func viewDidLoad() {
        // Do any additional setup after loading the view.
    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {

import UIKit

class MyCollectionCell: UICollectionViewCell {
    @IBOutlet var myWebImage: UIImageView!
    @IBOutlet var myPage:UIPageControl!

Those two IBOutlets are connected to the storyboard.

The error shows itself in the AppDelagate, although I haven’t used code there. Here is the code for that

import UIKit
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true

    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.


So I’ve located the bug, but I don’t understand it. The bug happens when I connect the collection view from the mainstory.board to the view controller. Specifically when I add the dataSource from the collection view to the view controller, how can I fix this, cause without this I just get a blanc screen on the sim?

This issue has been solved!