ios - Searchbar subview in UICollectionView delegate -
i trying add searchbar collectionview disappears when user swipes down collectionview view cell , images.
i able add searchbar without problems, when try hook delegate, crash:
-[uicollectionreusableview searchbar]: unrecognized selector sent instance 0x7fb30bc627f0 *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[uicollectionreusableview searchbar]: unrecognized selector sent instance 0x7fb30bc627f0'
the interface first view, main view's class looks like:
@interface okphotogalleryviewcontroller ()
here code viewdidload method:
[self.flickrcollectionview registernib:[uinib nibwithnibname:nsstringfromclass([oksearchbarphotogalleryviewcell class]) bundle:nil] forsupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:@"searchbar"]; uisearchbar *searchbar; [self.flickrcollectionview addsubview:searchbar];
and here viewforsupplementaryelementofkind method required:
- (uicollectionreusableview *)collectionview:(uicollectionview *)collectionview viewforsupplementaryelementofkind:(nsstring *)kind atindexpath:(nsindexpath *)indexpath{ static nsstring *searchbaridentifier = @"searchbar"; oksearchbarphotogalleryviewcell *collectionviewsearchbar = (oksearchbarphotogalleryviewcell *)[collectionview dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:searchbaridentifier forindexpath:indexpath]; collectionviewsearchbar.searchbar.delegate = self; return collectionviewsearchbar; }
where application crashes on line
collectionviewsearchbar.searchbar.delegate = self;
and class' header instantiating , adding subview inside of uicollectionview looks like:
@interface oksearchbarphotogalleryviewcell : uicollectionreusableview @property (nonatomic, strong) iboutlet uisearchbar *searchbar; @end
i've tried changing class names, because @ first searchbar.searchbar.delegate = self, , thought could've caused problems, didn't help. tried hook delegate searchbar in oksearchbarphotogalleryviewcell, still received same crash.
i solved last night creating searchbar, putting in right place, hooking delegate , adding on subview. works charm , searchbar delegate methods sends me messages correctly.
- (uicollectionreusableview *)collectionview:(uicollectionview *)collectionview viewforsupplementaryelementofkind:(nsstring *)kind atindexpath:(nsindexpath *)indexpath { static nsstring *searchbaridentifier = @"searchbar"; oksearchbarphotogalleryviewcell *collectionviewsearchbar = (oksearchbarphotogalleryviewcell *)[collectionview dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:searchbaridentifier forindexpath:indexpath]; uisearchbar *searchbar = [[uisearchbar alloc] initwithframe:cgrectmake(0, 0, cgrectgetwidth(collectionview.frame), 44)]; searchbar.autocorrectiontype = uitextautocorrectiontypeno; searchbar.delegate = self; [collectionviewsearchbar addsubview:searchbar]; return collectionviewsearchbar; }
Comments
Post a Comment