Given the following UITableViewController, why can’t I get any of the UISearchBarDelegate methods to be called? I’m omitting the UITableViewDelegate and UITableViewDataSource methods.
#import <UIKit/UIKit.h>
@interface OpportunitySearchViewController : UITableViewController <UISearchBarDelegate>
@end
#import "OpportunitySearchViewController.h"
@interface OpportunitySearchViewController ()
@end
@implementation OpportunitySearchViewController
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
NSLog(@"initWithCoder:");
};
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"self=%@ self.view=%@ ", self, [self view]);
}
- (void)viewDidUnload {
[super viewDidUnload];
NSLog(@"viewDidUnload");
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
NSLog(@"shouldAutorotateToInterfaceOrientation:");
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"searchBar:textDidChange:");
}
@end
I’ve confirmed that my Storyboard scene is configured to use the OpportunitySearchViewContoller class and I’ve confirmed that the UISearchBar on the scene has the First Responder set as it’s delegate. Although that might be wrong, but I couldn’t find a File’s Owner in the Storyboard interface.
Help would be appreciated.
Don’t connect the first responder to your class as the delegate. Drag from the search bar to the controller object itself and make that the connection to the
delegate.