I would like to allow users of my app to search for images using a UISearchBar
above a UICollectionView
. According to my understanding, a UICollectionView
must be in a UICollectionViewController
to work properly. However, Xcode won't let me put a search bar in a UICollectionViewController
. I also can't use a generic UIViewController
as the collection view won't work properly. How can I achieve the functionality that I want?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
It is not mandatory to have
UICollectionView
insideUICollectionViewController
.UICollectionView
is just likeUITableView
and can be added anywhere. All you need to do is implementUICollectionViewDelegate
andUICollectionViewDataSource
protocols. You can follow following tutorial Supplementary Header and add search bar as a supplementary header ofUICollectionView
.CollectionView + SearchBar with Swift3 + Storyboard implementation.
Creating the Header View:
Creating the Search Bar:
Create the reusable view custom class
Set the reusable view custom class
Create the search bar outlet
Trick: Connect the search bar delegate to COLLECTION VIEW class, the search bar outlet goes to the CUSTOM REUSABLE VIEW CLASS
Implement the CollectionView header method of protocol
Set the Searchbar delegate
And finally, your the search bar delegate methods will be called in your CollectionView Class