添加搜索栏以过滤uicollection视图

时间:2017-11-07 05:14:16

标签: ios swift uicollectionview uisearchbar

我关注this tutorial。程序执行停止

 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.
    }

程序执行在这两行停止

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

错误是

  

主题1:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)

。如何摆脱这个程序崩溃。如何在集合视图上实现搜索操作。您可以从此链接下载项目。 https://drive.google.com/file/d/1ZSahZtGlfpEoo0eu40pHQHBwm9SrtU3H/view?usp=sharing

1 个答案:

答案 0 :(得分:1)

您的collectionView电子插座尚未与故事板中的UICollectionView相关联,请将它们连接起来,然后它就能正常工作。

enter image description here