好吧,我把头发拉过来.我几乎可以肯定我在某一点上也有这个工作,现在它不起作用了.
我有一个UISearchBar嵌入在表格视图中的单元格.我将搜索栏声明为属性,我的视图控制器设置为UISearchBarDelegate.搜索栏已初始化,配置,一切看起来都很棒.它响应其他委托方法来限制输入的字符,处理取消按钮,但除此之外searchBarSearchButtonClicked.我到底做错了什么?
以下是我的设置基础知识:
ViewController.h
    @interface SearchMLSNumberViewController : UIViewController <UISearchBarDelegate>
    @property (strong, nonatomic) UISearchBar *searchField;
ViewController.m
// viewDidLoad
// init the search bar
self.searchField = [[UISearchBar alloc] init];
self.searchField.delegate = self;
self.searchField.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchField.placeholder = NSLocalizedString(@"Search", @"Search");
// in my cell setup
CGRect frame = cell.contentView.frame;
[self.searchField setFrame:frame];
[cell.contentView addSubview:self.searchField];
// here is the delegate call that never fires for me
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    NSLog(@"search button pressed");
}
我已经排除了我的所有tableview设置以及所有这一切,它似乎都运行正常.这就是杀了我的原因.一切正常,所有其他委托方法......除了搜索按钮返回.请告诉我,我做的事情很愚蠢.我没有选择.
更新 我已经弄清楚了为什么搜索按钮无法执行的罪魁祸首.我删除了所有其他搜索栏委托方法,它开始工作......所以我一直评论它们,直到我发现哪一个导致了问题.
这家伙是我的罪魁祸首:
- …在我的应用程序中,我必须在tableview的头部添加一个搜索栏.我能够添加搜索栏但问题是没有添加ios的默认搜索栏我可以添加自定义搜索栏吗?我正在给出一张图片,看看会有哪些类型的搜索栏...

iphone uisearchbar uisearchdisplaycontroller uisearchbardelegate ios
我在我的TopBar.m中写UISearchBar是这样的:
_tempSearchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(44, 0, 320 - 44, 43)];
_tempSearchBar.barStyle=UIBarStyleDefault;
_tempSearchBar.placeholder=@"??";
[self addSubview:_tempSearchBar];
结果是这样,是对的.

然后我在另一个类中编写UISearchDisplayController,如下所示:
_topBar.tempSearchBar.delegate = self;    
_searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_topBar.tempSearchBar contentsController:self];
[_searchDisplayController setDelegate:self];
[_searchDisplayController setSearchResultsDataSource:self];
UISearchBarDelegate是这样的:
#pragma mark -
#pragma mark UISearchBarDelegate
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    [_searchDisplayController setActive:YES animated:YES];
}
当我单击UISearchBar时,它显示如下,searchBar的框架被更改.为什么?

当我取消UISearchDisplayController时,它是这样的:

为什么框架改变了?UISearchDisplayController的宽度从320-44变为320?
谢谢.
uisearchbar uisearchdisplaycontroller uisearchbardelegate uisearchbardisplaycontrol ios
我有一个以下课程的应用程序:
@interface SearchViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate>
@property (nonatomic, retain) IBOutlet UISearchBar *search;
如何自定义UISearchBar?我想添加一个分段按钮以允许搜索选项(和/或/短语).
我使用Apple开发者网站的示例代码作为基础:http://developer.apple.com/library/ios/#samplecode/TableSearch/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007848-Intro -DontLinkElementID_2 它是一个简单的表搜索代码.我想要做的是用自己的数据填充一个表格,使用不同的单元格样式,并使用搜索栏搜索内容.现在我已经成功完成了我想要完成的所有工作,但是我想隐藏用户点击搜索栏时出现的范围栏.我尝试使用此处找到的方法设置scopeButtonTitles = nil:http://developer.apple.com/library/ios/#documentation/uikit/reference/UISearchBar_Class/Reference/Reference.html
但仍然会显示范围栏.如果您运行表搜索栏,您可以看到标题为"全部,设备,桌面,便携式"的范围栏,我尝试搜索包含这些值的数组,但从未找到过.那么有人可以告诉我如何隐藏范围栏.我应该实施哪些方法以及应该在哪里实施?
如标题中所述,我有兴趣在搜索栏外单击时从搜索栏中取消键盘.类似的问题在touchesBegan中使用了self.view.endEditing(true),但我没有运气.我不确定我是否遗漏了其他任何东西,或者我是否正确设置了我的搜索栏.
import UIKit
import MapKit
class AddressVC: UIViewController {
    @IBOutlet weak var searchBar: UISearchBar!
    var searchCompleter = MKLocalSearchCompleter()
    var searchResults = [MKLocalSearchCompletion]()
    @IBOutlet weak var searchResultsTableView: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()
        searchBar.delegate = self
    // Do any additional setup after loading the view, typically from a nib.
        searchResultsTableView.isHidden = true
        searchCompleter.delegate = self
    }
extension AddressVC: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
    searchCompleter.queryFragment = searchText
}
func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool {
    self.searchBar.endEditing(true)
    searchBar.resignFirstResponder() …我有这个代码:
extension VC : UISearchBarDelegate
{
    func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
        print("searchBarTextDidEndEditing")
    }
    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
        // searchBar.resignFirstResponder()
    }
}
searchBarCancelButtonClicked单击搜索时已触发,但searchBarTextDidEndEditing直到我打电话才触发  searchBar.resignFirstResponder()
我读了很多关于此的问题和答案,但我不明白为什么会发生这种情况,以及resignFirstResponder()这里做什么?
我试图以编程方式设置从左到右对齐的搜索栏文本,但似乎它在相反的方向(如英语)添加了文本,然后搜索没有结果。感谢任何人的帮助。