Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search result of UISearchDisplayController has other cell layout and behaviour than searched table

I am using storyboarding. I have an UITableView with one prototype cell. This cell is of style "subtitle". I have added a segue from the cell to the detailed view. So when the user taps a cell it will open the corresponding editor... That all works great.

Now I added a UISearchDisplayController an a UISearchBar, implemented the delegates. That works very well.

But in the search result table the cells are of style "default" and are not tapable. What do I have to do to get a result table looking and behaving like the "unsearched" table?

like image 721
Shingoo Avatar asked Nov 30 '11 21:11

Shingoo


3 Answers

I would like to contribute for 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 the cell from the parameter tableView

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

assign it directly from the TableView on the view so you have to replace this

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

with this

 UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
like image 80
jcubero Avatar answered Oct 16 '22 01:10

jcubero


Found the problem...

The method

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

pulled the cell from the tableView, which is in the result case not the tableView from the storyboard but the resultTableView from the SearchDisplayController.

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

like image 21
Shingoo Avatar answered Oct 16 '22 01:10

Shingoo


I've been using ios 7.0 and Xcode 5.0. I found that search display controller is using the same tableview layout as the delegate view controller. All you have to do is judge if the current tableview is the delegate view controller's tableview, or the search display controller's tableview. But remember to add the 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 that sentence, then the row of the table view of search display is only as high as a default row, which makes you think it doesn't look like the "unsearched" table.

like image 42
little pig Avatar answered Oct 15 '22 23:10

little pig