首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么UISearchBar在UISearchBarDelegate添加UISearchBar时不调用UISearchBar?

为什么UISearchBar在UISearchBarDelegate添加UISearchBar时不调用UISearchBar?
EN

Stack Overflow用户
提问于 2012-12-19 01:51:43
回答 1查看 330关注 0票数 1

我已经设置了UISearchBar的委托,但是为什么它在操作UISearchBarDelegate时不调用hospitalSearchBar。

TestViewController.h

代码语言:javascript
复制
#import "TestViewController.h"

@interface TestViewController : UIViewController<UISearchBarDelegate>

- (IBAction)buttonClick:(id)sender;

@end

TestViewController.m

代码语言:javascript
复制
#import "TestViewController.h"

@implementation TestViewController

- (IBAction)buttonClick:(id)sender
{
        UISearchBar *hospitalSearchBar = [[UISearchBar alloc] init];
        [hospitalSearchBar setDelegate:self];
        [hospitalSearchBar setShowsSearchResultsButton:YES];
        UIPickerView *hospitalPickerview = [[UIPickerView alloc] init];
        MAlertView *alert = [[MAlertView alloc] initWithTitle:@"" message:nil delegate:self cancelButtonTitle:@"提交" otherButtonTitles:@"cancel", nil];
        [alert addSearchBar:hospitalSearchBar placeHolder:@"Key Word"];
        [alert addPickerView:hospitalPickerView];
        [alert setDelegate:self];
        [alert show];
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{return YES;}

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{return YES;}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{[self endEditing:YES];}

@end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-19 03:21:52

您的代码给了我错误:)

不过,我的观点是,您要在一个delegate self) (带有delegate self)的子类)中添加UISearchBar

因此,在MAlertView中实现委托,您就可以在MAlertView类中检测到UISearchBar委托。

如果没有修复,请提供我的MAlertView类的全部实现细节。

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

https://stackoverflow.com/questions/13944431

复制
相关文章

相似问题

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