如何在表中加载特定行,然后根据按下按钮查看控制器

时间:2012-08-28 21:07:58

标签: ios

我发誓我在文档中看到了一些关于此的内容但找不到它(因为我不知道该找什么)。

基本上在我的应用程序中,第一个VC包含一个地图,用户可以在每个地图上选择注释和一个标注按钮。否则,用户还可以选择一个按钮,在地图上打开可搜索的建筑物表格,并加载显示详细信息的视图控制器(基本上是主 - 细节设置)。

我想要做的是让callout加载该特定建筑的指定路径。因此,如果我点击建筑物A上的标注,它会打开详细视图控制器以显示信息。

我该怎么做,或者哪​​些文档会有帮助?

1 个答案:

答案 0 :(得分:0)

从阅读本文来看,它听起来就像地图视图一样,表视图属于同一个视图控制器。如果是这样,那么视图控制器就是集中处理的地方。假设模型是一个数据对象数组,在控制器中有一个方法可以完成协调不同视图的所有工作。

- (void)selectModelAtIndex:(NSUInteger)index sender:(id)sender
{
    if (self.isSelectingModel)
        return;
    self.isSelectingModel = YES; // Stops recursive calls to -selectModelAtIndex:

    NSIndexPath *indexPath = [self indexPathForModelAtIndex:index];
    [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone;
    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNon animate:NO];

    MKAnnotation *annotation = [self annotationForModelAtIndex:index];
    [self.mapView selectAnnotation:av.annotation animated:NO];

    [self performSegueWithIdentifier:@"Identifier Of Detail View" sender:sender];

    self.isSelectingModel = NO;
}

这是一种单一方法,可以在切换到详细信息视图控制器之前使tableView和mapView保持同步。您需要拥有isSelectingModel属性,-indexPathForModelAtIndex:-annotationForModelAtIndex:

此方法由表视图调用,映射视图确实选择了回调。