Unable to get UISearchBar to appear on the toolbar (or anywhere) on the iPad

It really makes me adapt. I see a lot of information about placing the UISearchBar on the top line of the UITableView, but I put the UISearchBar in the toolbar at the top of the screen (on the iPad). I cannot find ANYTHING regarding how to handle the UISearchBar and UISearchDisplayController using the UIPopoverController on the iPad. It would be very helpful to get more information about the UISearchDisplayController using the UIPopoverController . Please help with this as I am at my witty end.

Using IB, I put the toolbar on IUView on the iPad. I added the following: Search Bar (not Search Bar and Search Display ) to the toolbar. I set the following parameters: Show the Cancel button, Show the visibility panel, Title buttons: Title1 and Title2 (when selecting the Title2 radio button). Opaque, transparent context and automatic resizing are checked. I connected the Search Bar delegate to File Owner and associated it with the IBOutlet theSearchBar .

In my viewWillAppear , I have the following:

  //Just in case: [theSearchBar setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]]; //Just in case (again): [theSearchBar setShowsScopeBar:YES]; //doesn't seem to do anything: //[theSearchBar sizeToFit]; searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:theSearchBar contentsController:self]; [self setSearchDisplayController:searchDisplayController]; [searchDisplayController setDelegate:self]; [searchDisplayController setSearchResultsDataSource:self]; //again--does not seem to do anything..but people have suggested it: [theSearchBar sizeToFit]; 

Okay, so far, I thought, so good. So, I made the File Owner .m file for the delegate for: UISearchBarDelegate, UISearchDisplayDelegate .

My problem: I have yet to implement the delegates needed to do the search, but still ... shouldn't I see the scopeBar next to the search field when I click in the search field? Just so you know that I see a log of characters that I print, so the delegate works.

Here is the routine I used to check if IB really placed the search bar (UISegementedControl) in the search bar:

 for (UIView *v in theSearchBar.subviews) { if ([v isMemberOfClass:[UISegmentedControl class]]) { // You've got the segmented control! UISegmentedControl *scope = (UISegmentedControl *)v; // Do your thing here... NSLog(@"Found Scope: '%@'\n",scope); NSLog(@"Scope Segments: '%d'\n",[v numberOfSegments]); } } 

It shows:

 [30013:207] Found Scope: '<UISegmentedControl: 0x68a06b0; frame = (0 0; 200 44); opaque = NO; layer = <CALayer: 0x68a0600>>' [30013:207] Scope Segments: '2' 

So, I know that there are 2 segments. I also know that they do not appear ... What am I doing wrong?

Why is the visibility bar not showing? The UIPopoverController results are displayed with the heading β€œResults” and β€œNo Results” (of course) when I type the first character in my search ... but does not have a frame. (not that I expect anything but "No results found."

I am wondering where the visibility panel should appear ... in the titleView of a UIPopover? On the toolbar to the right of the search area? Where?

+4
source share
2 answers
 [self.searchDisplayController searchBar] setScopeButtonTitles:[NSArray arrayWithObjects:@"Near Me",@"Everywhere",nil]]; 

This help may help.

0
source

UISearchBar does not display this area when embedded in UIToolbar, this is true even in iOS 7.

You must create your own UISegment and add it to the view of the search results table or create your own view to hold the UISearchBar, which displays the scope.

0
source

Source: https://habr.com/ru/post/1310322/


All Articles