给定下面的UITableViewController,为什么我不能调用任何UISearchBarDelegate方法?我省略了UITableViewDelegate和UITableViewDataSource方法。
#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我已经确认我的故事板场景被配置为使用OpportunitySearchViewContoller类,并且我已经确认场景中的UISearchBar将第一个响应器设置为它的代理。虽然这可能是错误的,但我在Storyboard界面中找不到文件的所有者。
如果能帮上忙,我们将不胜感激。
发布于 2012-07-24 13:27:14
不要将first responder作为委托连接到您的类。从搜索栏拖动到控制器对象本身,并将其作为到delegate的连接。
https://stackoverflow.com/questions/11624408
复制相似问题