Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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];

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.

There is a possible answer to this here. It may not work entirely for you, but as I explained, the UISearchDisplayController creates the table view.

Check the documentation and you can get a better understanding of it, but it states:

You initialize a search display controller with a search bar and a view controller responsible for managing the original content to be searched. When the user starts a search, the search display controller is responsible for superimposing the search interface over the original view controller’s view and showing the search results. The results are displayed in a table view that’s created by the search display controller. In addition to the original view controller, there are logically four other roles. These are typically all played by the same object, often the original view controller itself.

In my case UISearchDisplayController was using right cell type (custom) but height of cell was wrong so I had to use

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

method to fix it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top