来自searchResultsTableView的segue

时间:2012-12-10 10:59:01

标签: xcode4.5 segue uisearchdisplaycontroller

我目前有一个searchdisplaycontroller设置和工作。原始表视图具有为标题和图像设置的segue,以传递给详细视图。我想从搜索显示控制器发生这种情况,但这不会发生?我知道这是可能的,但似乎无法让它工作?我的代码是:

- (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

并在详细视图中设置全部:

- (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"]]];
    }
}

我非常感谢您解决这个问题的任何帮助:)

1 个答案:

答案 0 :(得分:1)

您可以通过调用performSegueWithIdentifier:sender:from tableView:didSelectRowAtIndexPath来搜索显示控制器:像这样:

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

然后在prepareForSegue:sender:你设置你的destinationViewController属性

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

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

       // Set your destinationViewController properties here

    }
}