user8298737
user8298737

Reputation:

Adding search bar to filter the uicollection View

I am following this tutorial .The program execution stops

 override func viewDidLoad() {
        super.viewDidLoad()

        collectionView.delegate=self /////error line 
        collectionView.dataSource=self /////error line

        self.searchController.searchResultsUpdater = self
        self.searchController.delegate = self
        self.searchController.searchBar.delegate = self

        self.searchController.hidesNavigationBarDuringPresentation = false
        self.searchController.dimsBackgroundDuringPresentation = true
        self.searchController.obscuresBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = "Search for tools and resources"
        searchController.searchBar.sizeToFit()

        searchController.searchBar.becomeFirstResponder()

        self.navigationItem.titleView = searchController.searchBar



        // Do any additional setup after loading the view, typically from a nib.
    }

the program execution stop at these two lines

 collectionView.delegate=self /////error line 
collectionView.dataSource=self /////error line

The error is

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

.How to get rid of this program crash.How to implement search operation on collection view.you can download the project from this link . https://drive.google.com/file/d/1ZSahZtGlfpEoo0eu40pHQHBwm9SrtU3H/view?usp=sharing

Upvotes: 0

Views: 1009

Answers (1)

Tj3n
Tj3n

Reputation: 9923

Your collectionView outlet have not been connected with the UICollectionView from Storyboard, Connect them, and then it will work.

enter image description here

Upvotes: 1

Related Questions