通过表视图和地图视图传递数据...它是如何工作的?
我的应用程序有一个带有两个视图的 TabBar。一个是地图,另一个是带有搜索字段的表格视图。在表视图控制器中,我通过 JSON 获取一些位置(带有坐标)。我需要知道如何检索这些信息以将注释放入地图中。
在表视图中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MapViewController *mvc = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
CLLocationCoordinate2D location;
titleLocation = [ streets objectAtIndex:indexPath.row ];
location.latitude = [ [ latitude objectAtIndex:indexPath.row ] doubleValue];
location.longitude = [ [ longitude objectAtIndex:indexPath.row ] doubleValue];
[self.tabBarController setSelectedIndex:0];
[mvc release];
我知道它不起作用,但我不知道如何将此值传递给 MapViewController 或我的 MapViewAnnotation,然后放入 MapViewController 中。我认为最后一个比第一个更好。
你能帮我吗? 非常感谢
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MapViewController *mvc = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
CLLocationCoordinate2D location;
titleLocation = [ streets objectAtIndex:indexPath.row ];
location.latitude = [ [ latitude objectAtIndex:indexPath.row ] doubleValue];
location.longitude = [ [ longitude objectAtIndex:indexPath.row ] doubleValue];
MapViewAnnotation *mva = [[MapViewAnnotation alloc] initWithTitle:titleLocation andSubtitle:@"Clique para fazer sua contribuição" andCoordinate:location];
NSLog(@"Lat/Log: %f/%f", location.latitude, location.longitude);
[mvc setAnnotation:mva];
[mvc.mapView addAnnotation:mva];
[self.tabBarController setSelectedIndex:0];
[mvc release];
}
我这样设置,但它仍然不起作用。注释不出现。
My app has a TabBar with two views. One is a map and other is a table view with search field. In table view controller I get some places (with coordinates) through JSON. I need to know how to retrieve these informations to put an Annotation in a map.
in TABLE VIEW:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MapViewController *mvc = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
CLLocationCoordinate2D location;
titleLocation = [ streets objectAtIndex:indexPath.row ];
location.latitude = [ [ latitude objectAtIndex:indexPath.row ] doubleValue];
location.longitude = [ [ longitude objectAtIndex:indexPath.row ] doubleValue];
[self.tabBarController setSelectedIndex:0];
[mvc release];
I know it will not work, but I don't know how to pass this values for MapViewController or my MapViewAnnotation then put into MapViewController. This last one I think is better then the first one.
Could you help me?
Thanks a lot
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MapViewController *mvc = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];
CLLocationCoordinate2D location;
titleLocation = [ streets objectAtIndex:indexPath.row ];
location.latitude = [ [ latitude objectAtIndex:indexPath.row ] doubleValue];
location.longitude = [ [ longitude objectAtIndex:indexPath.row ] doubleValue];
MapViewAnnotation *mva = [[MapViewAnnotation alloc] initWithTitle:titleLocation andSubtitle:@"Clique para fazer sua contribuição" andCoordinate:location];
NSLog(@"Lat/Log: %f/%f", location.latitude, location.longitude);
[mvc setAnnotation:mva];
[mvc.mapView addAnnotation:mva];
[self.tabBarController setSelectedIndex:0];
[mvc release];
}
I put like this but it still doesn't work. The Annotation doesn't appear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设地图始终位于选项卡索引 0 上,您可以使用选项卡栏控制器的
viewControllers
数组直接访问MapViewController
:makeAnnotationAtLocation:title:
方法可能如下所示:Assuming the map is always on tab index 0, you can access that
MapViewController
directly using the tab bar controller'sviewControllers
array:The
makeAnnotationAtLocation:title:
method might look like this: