UITableViewController <uisearchbardelegate>不调用UISearchBarDelegate方法</uisearchbardelegate>

时间:2012-07-24 04:59:08

标签: objective-c ios storyboard uitableview uisearchbar

鉴于以下UITableViewController,我为什么不能调用任何UISearchBarDelegate方法?我省略了UITableViewDelegateUITableViewDataSource方法。

#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

我已经确认我的Storyboard场景配置为使用OpportunitySearchViewContoller类,并且我已确认场景中的UISearchBar已将First Responder设置为其委托。虽然这可能是错的,但我在Storyboard界面中找不到文件所有者。

帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

请勿将第一响应者作为代理连接到您的班级。从搜索栏拖动到控制器对象本身,并将其连接到delegate