我已经设置了UISearchBar的委托,但是为什么它在操作UISearchBarDelegate时不调用hospitalSearchBar。
TestViewController.h
#import "TestViewController.h"
@interface TestViewController : UIViewController<UISearchBarDelegate>
- (IBAction)buttonClick:(id)sender;
@endTestViewController.m
#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发布于 2012-12-19 03:21:52
您的代码给了我错误:)
不过,我的观点是,您要在一个delegate self) (带有delegate self)的子类)中添加UISearchBar。
因此,在MAlertView中实现委托,您就可以在MAlertView类中检测到UISearchBar委托。
如果没有修复,请提供我的MAlertView类的全部实现细节。
https://stackoverflow.com/questions/13944431
复制相似问题