自定义UISearchBar和UISearchController问题

时间:2015-07-06 15:12:19

标签: ios objective-c uisearchbar uisearchcontroller

我想将更具体的问题发布到this one

我实现了自定义UISearchBar,因此实现了自定义UISearchController,因为这似乎是阻止搜索栏显示“取消”按钮的唯一解决方案。这确实解决了上述问题,但创造了一个新问题。出于某种原因,updateSearchResultsForSearchController:委托方法(viewController我已经实施searchController)的方法不再被调用(它是第一次点击searchBar时) ,但在输入搜索字符串时没有),而标准为UISearchControllerUISearchBar。因此,搜索结果表无法显示

以下是SearchBar.h

的代码
@interface SearchBar : UISearchBar

@end

SearchBar.m

#import "SearchBar.h"

@implementation SearchBar

- (void)setShowsCancelButton:(BOOL)showsCancelButton {
    // Do nothing...
}

- (void)setShowsCancelButton:(BOOL)showsCancelButton animated:(BOOL)animated {
    // Do nothing....
}

@end

以及SearchController.h

@interface SearchController : UISearchController

@end

SearchController.m

#import "SearchController.h"
#import "SearchBar.h"

@interface SearchController () {
SearchBar *_searchBar;
}
@end

@implementation SearchController

- (void)viewDidLoad {

    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];
}

- (SearchBar *)searchBar {

    if (_searchBar == nil) {
        _searchBar = [[SearchBar alloc] initWithFrame:CGRectZero];
    }
    return _searchBar;
}

@end

在MyViewController.h中,我订阅了以下协议:

@interface MyViewController : UIViewController <UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating>

任何人都可以看到我可能错过的内容吗?提前谢谢。

0 个答案:

没有答案