我有一個頂部的搜索欄的桌面視圖。當我點擊搜索時,它被呼叫到第一響應者並且鍵盤出現。搜索欄有一個取消按鈕,但是當表格爲空時,我希望用戶能夠點擊空表格行上的任意位置,以便將搜索欄和鍵盤作爲第一響應者。我該怎麼做呢?點擊空的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. HTML搜索欄點擊excel
- 3. 當我點擊空格鍵時,搜索欄中出現一個小點?
- 4. UitableView和Segue搜索欄
- 5. 隱藏UITableView搜索欄
- 6. 搜索欄來搜索TextViews
- 7. UITableView部分索引重疊搜索欄
- 8. 搜索時隱藏索引欄UITableView
- 9. 帶隱藏的UITableView的搜索欄iOS
- 10. 當用戶點擊/點擊以外時,使搜索欄消失
- 11. 的UITableView,搜索欄和部分指數
- 12. 在UIViewController裏面有UITableView的搜索欄
- 13. 帶搜索欄的UITableView問題
- 14. 的UITableView與搜索欄不XCode中6
- 15. 如何辭退的ViewController而navigationItem的搜索欄具有焦點
- 16. iPhone:默認隱藏UITableView搜索欄
- 17. 在UITableView上添加搜索欄
- 18. 如何在uitableview中添加搜索欄?
- 19. 搜索時出現搜索欄錯誤
- 20. 更改UISearchBar搜索按鈕上的UITableView數據源點擊
- 21. 退出搜索視圖
- 22. 搜索欄來過濾表
- 23. Datatables搜索點擊的div
- 24. 退出點擊x python
- 25. 點擊退出pygame窗口
- 26. 如何在導航欄下添加搜索欄並通過點擊搜索欄創建一個動作表
- 27. 如何在用戶點擊sectionIndex滾動條頂部的搜索圖標時出現Tableview中的搜索欄?
- 28. iOS版:的UISearchBar與UISearchdisplaycontroller墜毀通過點擊搜索欄
- 29. 可點擊區域搜索欄的更大顯示區域
- 30. 當點擊搜索時,Charms欄下方的項目被調用