Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UISearchController不会触发委托方法和搜索栏委托方法_Ios_Swift_Ios8 - Fatal编程技术网

Ios UISearchController不会触发委托方法和搜索栏委托方法

Ios UISearchController不会触发委托方法和搜索栏委托方法,ios,swift,ios8,Ios,Swift,Ios8,所以我有UISearchController,它显示栏,我可以输入文本,但它不会触发委托方法。这是我的密码: @IBAction func searchTapped(AnyObject) { NSLog("search...") let cancelButton = UIBarButtonItem(image: UIImage(named: "delete_sign-50"), landscapeImagePhone: nil, style: .Plain, target:

所以我有UISearchController,它显示栏,我可以输入文本,但它不会触发委托方法。这是我的密码:

@IBAction func searchTapped(AnyObject) {

    NSLog("search...")

    let cancelButton = UIBarButtonItem(image: UIImage(named: "delete_sign-50"), landscapeImagePhone: nil, style: .Plain, target: self, action: "cancelTapped:")

    var searchController = UISearchController(searchResultsController: nil)
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = "enter the text to search"
    searchController.searchResultsUpdater = self;
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.delegate = self
    searchController.searchBar.delegate = self

    self.definesPresentationContext = true;


    UIView.animateWithDuration(0.2, animations: { () -> Void in

        self.navigationItem.rightBarButtonItems = nil
        self.navigationItem.rightBarButtonItems = [cancelButton]
        self.navigationItem.titleView = searchController.searchBar
        searchController.searchBar.sizeToFit()
        self.toolbar.hidden = false
        self.tableView?.hidden = false
    })

    //add first responser to search bar
    searchController.searchBar.becomeFirstResponder()

}

func updateSearchResultsForSearchController(searchController: UISearchController) {

    NSLog("1 %@", searchController.searchBar.text);

}

func searchBar(searchBar: UISearchBar, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    NSLog("2 %@", text)
    return true
}
当文本更改时,这些方法都不会被调用

除此之外,我还尝试将searchController作为变量添加到我的控制器中,在这种情况下,它工作得很疯狂——当我点击搜索栏时,它就会离开屏幕

searchController.active = YES;
这很有帮助,但不知道为什么没有提到

这很有帮助,但不知道为什么没有提到

这很有帮助,但不知道为什么没有提到

这很有帮助,但不知道为什么没有提到它。

对于IOS 9

    -(void )viewDidLoad
 _searchController = [[UISearchController alloc] initWithSearchResultsController:self];
    self.navigationItem.titleView  = _searchController.searchBar;
    self.definesPresentationContext = YES;
    _searchController.delegate = self;
    _searchController.searchBar.delegate = self;
    _searchController.searchBar.placeholder = NSLocalizedString(@"SEARCHTITLE", nil);
    [_searchController.searchBar setShowsCancelButton: YES animated: NO];
对于IOS 9

    -(void )viewDidLoad
 _searchController = [[UISearchController alloc] initWithSearchResultsController:self];
    self.navigationItem.titleView  = _searchController.searchBar;
    self.definesPresentationContext = YES;
    _searchController.delegate = self;
    _searchController.searchBar.delegate = self;
    _searchController.searchBar.placeholder = NSLocalizedString(@"SEARCHTITLE", nil);
    [_searchController.searchBar setShowsCancelButton: YES animated: NO];
对于IOS 9

    -(void )viewDidLoad
 _searchController = [[UISearchController alloc] initWithSearchResultsController:self];
    self.navigationItem.titleView  = _searchController.searchBar;
    self.definesPresentationContext = YES;
    _searchController.delegate = self;
    _searchController.searchBar.delegate = self;
    _searchController.searchBar.placeholder = NSLocalizedString(@"SEARCHTITLE", nil);
    [_searchController.searchBar setShowsCancelButton: YES animated: NO];
对于IOS 9

    -(void )viewDidLoad
 _searchController = [[UISearchController alloc] initWithSearchResultsController:self];
    self.navigationItem.titleView  = _searchController.searchBar;
    self.definesPresentationContext = YES;
    _searchController.delegate = self;
    _searchController.searchBar.delegate = self;
    _searchController.searchBar.placeholder = NSLocalizedString(@"SEARCHTITLE", nil);
    [_searchController.searchBar setShowsCancelButton: YES animated: NO];

是否确认了UISearchController委托。是否确认了UISearchController委托。是否确认了UISearchController委托。是否确认了UISearchController委托。