
我在vIEwDIDLoad中设置它:
self.searchController = [[UISearchdisplayController alloc] initWithSearchbar:self.searchbar contentsController:self];self.searchController.delegate = self;self.searchController.searchResultsDataSource = self;self.searchController.searchResultsDelegate = self;[self.collectionVIEw addSubvIEw:self.searchbar];
当我将另一个视图控制器推送到导航控制器然后d出它时,搜索栏消失.仅当集合视图向下滚动到足以隐藏搜索栏时才会发生这种情况.此外,即使搜索栏消失,点击它应该激活的白色空间也会激活附加到它的搜索显示控制器.
这仅在iOS 7上发生,如果我删除搜索显示控制器,搜索栏将不会消失.
还有一件事值得一提.当搜索栏消失时,如果我按下另一个视图控制器然后d出它,则该栏将再次可见.
显然这是iOS 7上UISearchdisplayController的一个BUG,所以关于如何解决它的任何想法?
解决方法 我最终自己实现了UISearchdisplayController.这是我的代码.ZBNSearchdisplayController.h
@protocol ZBNSearchdisplayDelegate;@interface ZBNSearchdisplayController : NSObject<UISearchbarDelegate>- (ID)initWithSearchbar:(UISearchbar *)searchbar contentsController:(UIVIEwController *)vIEwController;- (voID)setActive:(BOol)visible animated:(BOol)animated;@property(nonatomic,assign) ID<ZBNSearchdisplayDelegate> delegate;@property(nonatomic,getter = isActive) BOol active;@property(nonatomic,Readonly) UISearchbar *searchbar;@property(nonatomic,Readonly) UIVIEwController *searchContentsController;@property(nonatomic,Readonly) UItableVIEw *searchResultstableVIEw;@property(nonatomic,assign) ID<UItableVIEwDataSource> searchResultsDataSource;@property(nonatomic,assign) ID<UItableVIEwDelegate> searchResultsDelegate;@end@protocol ZBNSearchdisplayDelegate <NSObject>@optional- (voID)searchdisplayControllerWillBeginSearch:(ZBNSearchdisplayController *)controller;- (voID)searchdisplayControllerDIDBeginSearch:(ZBNSearchdisplayController *)controller;- (voID)searchdisplayControllerWillEndSearch:(ZBNSearchdisplayController *)controller;- (voID)searchdisplayControllerDIDEndSearch:(ZBNSearchdisplayController *)controller;- (voID)textDIDChange:(Nsstring *)searchText;- (voID)searchbar:(UISearchbar *)searchbar selectedScopebuttonIndexDIDChange:(NSInteger)selectedScope;@end
ZBNSearchdisplayController.m
#import "ZBNSearchdisplayController.h"@implementation ZBNSearchdisplayController- (ID)initWithSearchbar:(UISearchbar *)searchbar contentsController:(UIVIEwController *)vIEwController { self = [super init]; if (self) { _searchbar = searchbar; _searchbar.delegate = self; _searchContentsController = vIEwController; CGfloat y = 64.0f; CGfloat height = _searchContentsController.vIEw.frame.size.height - y; _searchResultstableVIEw = [[UItableVIEw alloc] initWithFrame:CGRectMake(0.0f,y,_searchContentsController.vIEw.frame.size.wIDth,height)]; _searchResultstableVIEw.scrollsTotop = NO; } return self;}- (voID)setSearchResultsDataSource:(ID<UItableVIEwDataSource>)searchResultsDataSource { _searchResultstableVIEw.dataSource = searchResultsDataSource;}- (voID)setSearchResultsDelegate:(ID<UItableVIEwDelegate>)searchResultsDelegate { _searchResultstableVIEw.delegate = searchResultsDelegate;}- (voID)setActive:(BOol)visible animated:(BOol)animated { if (!visible) { [_searchbar resignFirstResponder]; _searchbar.text = nil; _searchbar.showsCancelbutton = NO; } if (visible && [self.delegate respondsToSelector:@selector(searchdisplayControllerWillBeginSearch:)]) { [self.delegate searchdisplayControllerWillBeginSearch:self]; } else if (!visible && [self.delegate respondsToSelector:@selector(searchdisplayControllerWillEndSearch:)]) { [self.delegate searchdisplayControllerWillEndSearch:self]; } [_searchContentsController.navigationController setNavigationbarHIDden:visible animated:YES]; float Alpha = 0; if (visible) { [_searchContentsController.vIEw addSubvIEw:_searchResultstableVIEw]; Alpha = 1.0; } if ([_searchContentsController.vIEw respondsToSelector:@selector(scrollEnabled)]) { ((UIScrollVIEw *)_searchContentsController.vIEw).scrollEnabled = !visible; } if (animated) { [UIVIEw animateWithDuration:0.2 animations:^{ _searchResultstableVIEw.Alpha = Alpha; } completion:^(BOol finished) { self.active = visible; }]; } else { _searchResultstableVIEw.Alpha = Alpha; }}#pragma mark - UISearchbarDelegate- (voID)searchbar:(UISearchbar *)searchbar selectedScopebuttonIndexDIDChange:(NSInteger)selectedScope { if ([self.delegate respondsToSelector:@selector(searchbar:selectedScopebuttonIndexDIDChange:)]) { [self.delegate searchbar:searchbar selectedScopebuttonIndexDIDChange:selectedScope]; }}- (voID)searchbar:(UISearchbar *)searchbar textDIDChange:(Nsstring *)searchText { if ([self.delegate respondsToSelector:@selector(textDIDChange:)]) { [self.delegate textDIDChange:searchText]; }}- (voID)searchbarTextDIDBeginEditing:(UISearchbar *)searchbar { [searchbar setShowsCancelbutton:YES animated:YES]; [self setActive:YES animated:YES]; [_searchResultstableVIEw reloadData];}- (voID)searchbarSearchbuttonClicked:(UISearchbar *)searchbar { [_searchResultstableVIEw reloadData];}- (voID)searchbarCancelbuttonClicked:(UISearchbar *)searchbar { [self setActive:NO animated:YES]; [self.searchResultstableVIEw scrollRectToVisible:CGRectMake(0,1,1) animated:NO];}@end 总结 以上是内存溢出为你收集整理的ios – UICollectionView中的UISearchBar在使用UISearchDisplayController时消失全部内容,希望文章能够帮你解决ios – UICollectionView中的UISearchBar在使用UISearchDisplayController时消失所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)