我有一個頂部的搜索欄的桌面視圖。當我點擊搜索時,它被呼叫到第一響應者並且鍵盤出現。搜索欄有一個取消按鈕,但是當表格爲空時,我希望用戶能夠點擊空表格行上的任意位置,以便將搜索欄和鍵盤作爲第一響應者。我該怎麼做呢?點擊空的UITableView來退出搜索欄
回答
您將不得不創建自己的覆蓋touchesEnded方法的UITableView類。然後你可以回叫你的委託人,委託人應該是你的視圖控制器,並告訴它告訴你的UISearchBar辭去第一響應者。
的UITableView的派生類會是這個樣子:
#import <UIKit/UIKit.h>
@interface FRTableView : UITableView {
}
@end
// ------------------------------
#import "FRTableView.h"
@implementation FRTableView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
NSLog(@"Touches ended");
// Bubble back up to your view controller which should be this
// table view's delegate.
if ([self delegate] && [[self delegate] respondsToSelector:@selector(touchEnded)])
[[self delegate] performSelector:@selector(touchEnded)];
}
@end
請務必設置在Interface Builder你的表視圖中使用自定義類,而不是正常的UITableView類的。然後在您的視圖控制器,實現選擇,我叫touchEnded這樣的:
- (void)touchEnded;
{
NSLog(@"Back in root view controller.");
[searchBar resignFirstResponder];
}
在哪裏搜索欄是連接在Interface Builder一個UISearchBar一個IBOutlet。
Ÿ不ü嘗試...... UISearchDisplayController
只要定義這些在烏拉圭回合.h文件中
IBOutlet中的UISearchBar * mySearchBar; UISearchDisplayController * mySearchDisplayController; IBOutlet UITableView * myTableView;
和.H
現在在.m文件處理UISearchBarDelegate只寫這些代碼
mySearchDisplayController = [[UISearchDisplayController的alloc] initWithSearchBar:mySearchBar contentsController:自]; mySearchDisplayController.searchResultsDelegate = self; mySearchDisplayController.searchResultsDataSource = self; mySearchDisplayController.delegate = self;
我希望這可以幫到.......
- 1. UITableView搜索欄?
- 2. 點擊後的搜索欄
- 3. HTML搜索欄點擊excel
- 4. SQLite +搜索欄+ uitableview
- 5. 不使用搜索欄來過濾UITableView
- 6. 搜索沒有搜索欄的UITableView
- 7. 點擊時刪除搜索欄的值
- 8. UitableView和Segue搜索欄
- 9. 隱藏UITableView搜索欄
- 10. 當我點擊空格鍵時,搜索欄中出現一個小點?
- 11. 搜索欄來搜索TextViews
- 12. jQuery點擊事件搜索欄
- 13. GMSAutocompleteViewController想要獲取搜索欄上的文本搜索點擊
- 14. UITableView部分索引重疊搜索欄
- 15. 搜索時隱藏索引欄UITableView
- 16. 帶隱藏的UITableView的搜索欄iOS
- 17. 當用戶點擊/點擊以外時,使搜索欄消失
- 18. 搜索欄控制器的UITableView
- 19. 原創的UITableView使用搜索欄
- 20. 帶搜索欄的UITableView問題
- 21. 的UITableView,搜索欄和部分指數
- 22. 的UITableView與搜索欄不XCode中6
- 23. 在UIViewController裏面有UITableView的搜索欄
- 24. 當點擊圖標時導航欄中的搜索欄
- 25. 通過點擊鍵盤上的搜索來觸發搜索
- 26. 如何辭退的ViewController而navigationItem的搜索欄具有焦點
- 27. 點擊彈出式搜索框中的搜索圖標
- 28. 將搜索欄添加到UITableView頂部
- 29. 如何在UITableView上顯示搜索欄
- 30. iPhone:默認隱藏UITableView搜索欄