首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewController<UISearchBarDelegate>不调用UISearchBarDelegate方法

UITableViewController<UISearchBarDelegate>不调用UISearchBarDelegate方法
EN

Stack Overflow用户
提问于 2012-07-24 12:59:08
回答 1查看 322关注 0票数 0

给定下面的UITableViewController,为什么我不能调用任何UISearchBarDelegate方法?我省略了UITableViewDelegateUITableViewDataSource方法。

代码语言:javascript
复制
#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界面中找不到文件的所有者。

如果能帮上忙,我们将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-24 13:27:14

不要将first responder作为委托连接到您的类。从搜索栏拖动到控制器对象本身,并将其作为到delegate的连接。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11624408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档