I have UICollectionviewbuilt in UIViewController. In addition, I added a search string to the UIViewController, as in the UICollectionview. I do not know where it can be carried through the Storyboard. I expected searching in UICollectionviewwould be as simple as in Tableview. But he seems to have his own rules. Is there a good and simple example showing how to implement a simple search in UICollectionview, as in UITableview? I want the user to be able to enter a search string, but UICollectionviewdisplays the results. I found a solution to implement searchbar:
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.collectionView.frame), 44)];
self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchBar.delegate = self;
[self.collectionView addSubview:self.searchBar];
[self.collectionView setContentOffset:CGPointMake(0, 44)];
}
- (void) viewWillAppear:(BOOL)animated{
[self.collectionView setContentOffset:CGPointMake(0, 0)];
[self.collectionView setContentOffset:CGPointMake(0, 44)];
}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[searchBar setShowsCancelButton:YES animated:YES];
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
[searchBar setText:@""];
[searchBar setShowsCancelButton:NO animated:YES];
[searchBar resignFirstResponder];
}
, searchbar, , , searchbar . , ? - .
