3
我在UITableView
中添加了UISearchBar
並將其添加到UIView
之內。我在窗口上添加了UIView
,一切正常。 searchBarShouldBeginEditing
正在觸發並顯示日誌,但searchBarTextDidBeginEditing
未觸發。下面是我的代碼:UISearchBar無響應
AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
self.frame = appDelegate.window.frame;
[appDelegate.window addSubview:self];
內myView.h
:
@property(strong, nonatomic) UISearchController *searchController;
和內部myView.m
:
- (void)drawRect:(CGRect)rect {
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
[self.searchController.searchBar sizeToFit];
self.searchController.searchBar.userInteractionEnabled = YES;
tblDropdown.tableHeaderView = self.searchController.searchBar;
arrSeached = [NSMutableArray array];
}
https://www.google.com/search?q=searchBarTextDidBeginEditing&oq=searchBarTextDidBeginEditing&aqs=chrome..69i57j0l2.446j0j8&sourceid=chrome&ie=UTF-8# q = searchBarTextDidBeginEditing + not + –
drawRect不得用於僅爲繪圖添加視圖。如果你想添加一個子視圖,你可以在視圖控制器的初始化器或viewDidLoad中完成 –