1\初始化
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 20, 200, 30)];
[self.view addSubview:searchBar];
searchBar.delegate = self;
2\实现代理方法
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
NSLog(@"开始编辑");
[self presentViewController:[[redViewController alloc] init] animated:YES completion:nil];
return YES;
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"改变了");
}
时间: 2024-11-13 07:30:38