【发布时间】:2017-05-04 10:01:43
【问题描述】:
我在UITableView 中添加了UISearchBar,然后在UIView 中添加了它。我在窗口上添加UIView,一切正常。 searchBarShouldBeginEditing 正在触发并显示日志,但是 searchBarTextDidBeginEditing 没有触发。以下是我的代码:
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];
}
【问题讨论】:
-
drawRect 不能用于添加仅用于绘图的视图。如果要添加子视图,可以在初始化程序或视图控制器的 viewDidLoad 中进行
标签: ios uitableview uisearchbar uisearchcontroller