UISearchBarのデリゲートをすでに設定しましたが、hospitalSearchBarのUISearchBarDelegate
操作中に呼び出されないのはなぜですか。
TestViewController.h
#import "TestViewController.h"
@interface TestViewController : UIViewController<UISearchBarDelegate>
- (IBAction)buttonClick:(id)sender;
@end
TestViewController.m
#import "TestViewController.h"
@implementation TestViewController
- (IBAction)buttonClick:(id)sender
{
UISearchBar *hospitalSearchBar = [[UISearchBar alloc] init];
[hospitalSearchBar setDelegate:self];
[hospitalSearchBar setShowsSearchResultsButton:YES];
UIPickerView *hospitalPickerview = [[UIPickerView alloc] init];
MAlertView *alert = [[MAlertView alloc] initWithTitle:@"" message:nil delegate:self cancelButtonTitle:@"提交" otherButtonTitles:@"cancel", nil];
[alert addSearchBar:hospitalSearchBar placeHolder:@"Key Word"];
[alert addPickerView:hospitalPickerView];
[alert setDelegate:self];
[alert show];
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{return YES;}
- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{return YES;}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{[self endEditing:YES];}
@end