David
David

Reputation: 319

segue from searchResultsTableView

I currently have a searchdisplaycontroller set up and working. The original table view has a segue set up for the title and image to be passed to a detail view. I would like this segue to happen from the search display controller but this is not happening? I know this is possible but can't seem to get it to work? My code is:

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        [self.detailViewController setDetailItem:[[contentsList objectAtIndex:indexPath.section]
                                                  objectAtIndex: indexPath.row]];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"detailview"]) {
           self.detailViewController=segue.destinationViewController;
    }
}

@end

and in the detail view to set it all up:

- (void)setDetailItem:(id)newDetailItem
{
    if (_detailItem != newDetailItem) {
        _detailItem = newDetailItem;

        // Update the view.
        [self configureView];
    }
}

- (void)configureView
{
    // Update the user interface for the detail item.

    if (self.detailItem) {
        self.navigationItem.title = [self.detailItem objectForKey:@"name"];
        [self.detailImage setImage:[UIImage imageNamed:self.detailItem[@"image"]]];
    }
}

I would be very grateful for any help in solving this issue :)

Upvotes: 1

Views: 271

Answers (1)

Guto Araujo
Guto Araujo

Reputation: 3854

You can Segue from a Search Display Controller by calling performSegueWithIdentifier:sender: from tableView:didSelectRowAtIndexPath: like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     // Get the UITableViewCell that was selected
     UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

     // Then this will call prepareForSegue:sender: with selectedCell as sender
     [self performSegueWithIdentifier:@"detailview" sender:selectedCell];  
}

Then on prepareForSegue:sender: you set your destinationViewController properties

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"detailview"]) {

       // Set your destinationViewController properties here

    }
}

Upvotes: 1

Related Questions