UISearchDisplayController search result has a different cell structure and behavior than the search table

I use a storyboard. I have a UITableView with one prototype cell. This cell has a subtitle style. I added a section from the cell to the detail view. Therefore, when a user deletes a cell, he will open the corresponding editor ... This all works fine.

Now I have added UISearchDisplayController and UISearchBar, implemented delegates. It works very well.

But in the table of search results, the cells have the default style and are not displayed. What do I need to do to get a result table that looks and behaves like an "unsearched" table?

+6
source share
5 answers

Found a problem ...

Method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

pulled out a cell from the table View, which is in the resulting case, not tableView from the storyboard, but resultTableView from SearchDisplayController.

Now I get a cell to display in both cases from the table view in the storyboard, and now it works.

+8
source

I would like to contribute to answer # 1, this is what I did and it worked for me.

in the method

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

instead of assigning a cell from the tableView parameter

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

Assign it directly from the TableView in the view, so you need to replace this

 // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

with this

  UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
+24
source

I am using ios 7.0 and Xcode 5.0. I found that the search display controller uses the same table layout as the delegate view controller. All you have to do is judge if the current table view is the table view of the delegate view manager or the table view of the display controller. But don't forget to add a sentence

 tableView.rowHeight = self.tableView.rowHeight; 

in the following code snippet:

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. if (tableView == self.searchDisplayController.searchResultsTableView) { tableView.rowHeight = self.tableView.rowHeight;//very important! return [self.searchResults count]; } else { ... return ...; } } 

if you forget to implement this sentence, then the row of the lookup display lookup table will only be the same as the default row, which makes you think that this is not like the "unsearched" table.

+3
source

Here you can answer to. It may not work completely for you, but as I explained, UISearchDisplayController creates a table view.

Check the documentation and you can better understand it, but it says:

You initialize the search display controller using the search bar and the view manager responsible for managing the original search content. When the user starts the search, the search display controller is responsible for overlaying the search interface on the original view controllers and displaying the search results. The results are displayed in the form of a table created by the search display controller. In addition to the original controller, there are logically four other roles. Usually they play the same object, often the original view controller itself.

0
source

In my case, the UISearchDisplayController used the right cell type (custom), but the cell height was wrong, so I had to use

 (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

to fix it.

0
source

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


All Articles