I have already set UISearchBar’s delegate but why does it not invoke UISearchBarDelegate while operation hospitalSearchBar.
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
Your code given me errors 🙂
However my view is , you are adding the
UISearchBarinside aMAlertView(subclass withdelegate self) .So implement the delegates inside the
MAlertViewand you can detect theUISearchBardelegates inMAlertViewclass.If it not fixed, please provide me full implementation details of
MAlertViewclass.