我有一个UISearchBar,当用户点击键盘上的搜索按钮时,我想将结果加载到我拥有的另一个ViewController中,但是当我按下“搜索”按钮时没有任何反应。
这是我的代码:
#import "BuscadorViewController.h"
#import "EventosViewController.h"
@interface BuscadorViewController ()<UISearchBarDelegate>
@end
@implementation BuscadorViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
#pragma mark - UISearchBarDelegate Methods
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
[self loadViewResults];
}
#pragma mark - Methods
-(void)loadViewResults
{
NSString *title = self.searchBar.text;
EventosViewController *evc = [self.storyboard instantiateViewControllerWithIdentifier:@"listaEventosID"];
evc.parametro = title;
[self.navigationController presentViewController:evc animated:YES completion:nil];
// [self.navigationController pushViewController:evc animated:YES];
}
任何帮助都会非常感激。感谢。
答案 0 :(得分:0)
我没有看到你设置代表的任何地方..你必须为此设置委托。
- (void)viewDidLoad {
[super viewDidLoad];
self.searchBar.delegate = self;
}
并使用下面的代码肯定会有效。确保你必须在故事板中设置视图控制器关系。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"listaEventosID"]) {
NSString *title = self.searchBar.text;
evc.parametro = title;
}
}
-(void)loadViewResults
{
[self performSegueWithIdentifier:@"listaEventosID" sender:nil];
}