UISearchBar's Cancel and Clear Buttons Not Working in iOS 7

前端 未结 6 1068
生来不讨喜
生来不讨喜 2020-12-07 02:09

I have an xCode project that contains a tableview with a “Search Bar and Search Display Controller” to allow the user to refine the list of displayed items. In general, the

6条回答
  •  广开言路
    2020-12-07 02:26

    I googled all over internet and couldn't find a solution. so i changed the UItableview behaviour.

    instead of [searchBar becomeFirstResponder]; I scroll down the tableview.

    - (IBAction)goToSearch:(id)sender {
    
     scroll down to show the table.
    //    CGRect newBounds = self.TableView.bounds;
    //    newBounds.origin.y =0;
    //    
    //    self.TableView.bounds = newBounds;
    //[searchBar becomeFirstResponder];
    
        CGPoint contentOffset=self.TableView.contentOffset;
        contentOffset.y=0;
        [self.TableView setContentOffset:contentOffset animated:YES];
    
    
    }
    

    in my ViewDidload:

    //        CGRect newBounds = self.TableView.bounds;
    //        newBounds.origin.y = newBounds.origin.y + searchBar.bounds.size.height;
            // self.TableView.bounds = newBounds;
    
            CGPoint contentOffset=self.TableView.contentOffset;
            contentOffset.y=self.TableView.bounds.origin.y + searchBar.bounds.size.height;
            self.TableView.contentOffset=contentOffset;
    

    If found for some reasons, in iOS 7 , change table view bounds cause search bar to disappear. Hope that helps.

提交回复
热议问题