1

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


测试视图控制器.h

#import "TestViewController.h"

@interface TestViewController : UIViewController<UISearchBarDelegate>

- (IBAction)buttonClick:(id)sender;

@end

测试视图控制器.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
4

1 回答 1

0

你的代码给了我错误:)

然而我的观点是,你在UISearchBar里面添加了一个MAlertView子类delegate self

所以在里面实现委托,你可以在类MAlertView中检测到UISearchBar委托。MAlertView

如果它没有修复,请向我提供课程的完整实施细节MAlertView

于 2012-12-19T03:21:52.297 回答