I Added UISearchBar in UINavigationBar and its showing also but the delegate methods are not working. My code is as follows:
MainViewController.h
@interface MainViewController : UIViewController<UISearchBarDelegate> {
}
@property(nonatomic, readonly) UISearchBar *_searchBar;
@property(nonatomic, assign) id<UISearchBarDelegate> delegate;
MainViewController.m
-(void)viewDidLoad {
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(320.0, 0.0, 320.0, 44.0)];
_searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:_searchBar];
_searchBar.delegate = self;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"textDidChange is firing with %@",searchText);
}
Its not showing even the typed text only! Please give me suggestions.Thank You!