搜索键在ios中按下时没有任何反应 [英] Nothing happens when search key presses in ios

查看:67
本文介绍了搜索键在ios中按下时没有任何反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS开发的新手。我想在我的应用中添加一个搜索栏。当触摸搜索栏时,键盘会弹出。但是当我按下搜索按钮时,它不会关闭键盘。我的控制器.h文件如下。





 @ interface SearchViewController:
UIViewController< ; UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate> {

IBOutlet UISearchBar * searchBar;
IBOutlet UITableView * tableView;
NSMutableArray * listOfItems;
NSMutableArray * copyListOfItems;
NSArray *歌曲;
BOOL搜索;
BOOL letUserSelectRow;
}
@property(强大的,非原子的)NSArray *歌曲;
@property(强,非原子)UITableView * tableView;
@property(强,非原子)UISearchBar * searchBar;
@end







我在.m文件中实现了以下方法。但他们没有调用。



  - ( void )searchBarSearchButtonClicked :(UISearchBar *)searchBar {
NSLog( @ 搜索点击);
[self.searchBar resignFirstResponder];
}

- ( void )searchBarCancelButtonClicked:(UISearchBar *)searchBar {
NSLog( @ 取消点击);
}





有人能解释一下原因吗?

解决方案

< blockquote>

我没有看到任何引用链接到搜索按钮的UIButton类或IBOutlet或者捕获按钮点击事件的IBAction方法。

我想你会发现以下链接很有用:

http://klanguedoc.hubpages.com/hub/IOS-5-Tutorial-on-How-To-Dismiss-the-UI-Keyboard [ ^ ]



如果您在阅读上述链接中的文章后仍然遇到问题,只需在.h文件中添加一个喊叫:)


添加委托并初始化声明

  @ interface  RestaurantViewController:UIViewController< ui searchdisplaydelegate,> 

UISearchDisplayController * resName_search;
UISearchBar * mySearchBar;




.m文件中的


 mySearchBar = [[UISearchBar alloc] init]; 
[mySearchBar setDelegate: self ];
// [mySearchBar setShowsCancelButton:YES animated:NO];
resName_search = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController: self ];
resName_search.delegate = self ;
resName_search.searchResultsDataSource = self ;
resName_search.searchResultsDelegate = self ;
[ self .view addSubview:resName_search.searchBar];
[resName_search.searchBar setFrame:CGRectMake( 0 0 ,barOriginY + 79。 0 106 0 40 0 )];

- ( BOOL )searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
NSLog( @ 输入文字点击);

返回 ;
}
- ( BOOL )searchBarShouldEndEditing:(UISearchBar *)searchBar
{

NSLog(< span class =code-string> @ 取消点击);
返回 ;

}


I'm really new to iOS development. I wanted to add a search bar to my app. When touching on the search bar key board pops up. But when I press the search button it doesn't dismiss the keyboard. My controller .h file is as belows.


@interface SearchViewController : 
UIViewController<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate>{
    
    IBOutlet UISearchBar *searchBar;
    IBOutlet UITableView *tableView;
    NSMutableArray *listOfItems;
    NSMutableArray *copyListOfItems;
    NSArray *songs;
    BOOL searching;
    BOOL letUserSelectRow;
}
@property(strong,nonatomic)NSArray *songs;
@property(strong,nonatomic)UITableView *tableView;   
@property(strong,nonatomic)UISearchBar *searchBar;
@end




I have implemented the following methods in .m file. But they don't invoke.

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
     NSLog(@"search clicked");
    [self.searchBar resignFirstResponder];
}

-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
    NSLog(@"Cancel Clicked");
}



Can anybody explain me the reason?

解决方案

Hi,
I don't see any reference to a UIButton class or IBOutlet linked to the search button or an IBAction method that will capture the button click event.
I think you will find the following link useful:
http://klanguedoc.hubpages.com/hub/IOS-5-Tutorial-on-How-To-Dismiss-the-UI-Keyboard[^]

If you still have problems after going through the article in above link, just put a shout :)


in .h file add delegate and initialize declare

@interface RestaurantViewController : UIViewController <uisearchdisplaydelegate,>

    UISearchDisplayController      *resName_search;
    UISearchBar *mySearchBar;



in .m file

    mySearchBar = [[UISearchBar alloc]init];
    [mySearchBar setDelegate:self];
//    [mySearchBar setShowsCancelButton:YES animated:NO];
    resName_search = [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self];
    resName_search.delegate = self;
    resName_search.searchResultsDataSource = self;
    resName_search.searchResultsDelegate = self;
    [self.view addSubview:resName_search.searchBar];
   [resName_search.searchBar setFrame:CGRectMake(0.0, barOriginY+79.0, 106.0, 40.0)];

-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
NSLog(@" enter text clicked");

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

 NSLog(@"cancel clicked");
   return YES;

}


这篇关于搜索键在ios中按下时没有任何反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆