开发者

Can I insert a button in a UISearchDisplayController?

开发者 https://www.devze.com 2023-02-22 21:27 出处:网络
When a user has tapped in a search bar,hasn\'t entered any text, and the screen has been darkened (but the tableview has not appeared yet), I would开发者_运维问答 like to put a button on the screen to

When a user has tapped in a search bar, hasn't entered any text, and the screen has been darkened (but the tableview has not appeared yet), I would开发者_运维问答 like to put a button on the screen to allow the user to navigate away to some other functionality. Is that possible?

Thanks!


This is quite tricky. The _dimmingView is private to the searchDisplayController and it goes above all subviews. What you can do is cover it with your custom view every time it appears ([searchString length] == 0 and DidBeginSearch)

(tempView's frame is set for UISearchBar placed on table's tableViewHeader)

- (void)viewDidLoad {
    tempView = [[UIView alloc] initWith...];
    // tempView setup
    ...
}

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
    [tempView setFrame:CGRectMake(0, self.searchDisplayController.searchBar.frame.size.height, 320, self.searchDisplayController.searchResultsTableView.frame.size.height)];
    [self.searchDisplayController.searchContentsController.view addSubview:tempView];
    ...
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    if ([searchString length] == 0) 
         [self.searchDisplayController.searchContentsController.view addSubview:tempView];
    else 
         [tempView removeFromSuperview];
    ...
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
    if (tempView && tempView.superview) 
        [tempView removeFromSuperview];
    ...
}

Notes: I tried creating a new instance on DidBeginSearch and releasing it on DidEndSearch, and it worked only for the 1st call! Weird...

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消