ios - 将 didSelectRowAtIndexPath 与 UISplitViewController 和谷歌地图一起使用

标签 ios uitableview uinavigationcontroller uisplitviewcontroller gmsmapview

我在 UINavigationController 内部使用 UITableViewController 为我的 Master 使用 UIViewController 在 UINavigationController 内部实现 GMSMapViewDelegate 为我的详细信息端显示谷歌地图。目前,表格 View 和谷歌地图在 UISplitViewController 中显示良好。

我是一名初学者,最近读完了 Objective C 编程和 Big Nerd Ranch 的 IOS 7 指南。我不知道如何使用 didSelectRowAtIndexPath 方法通过 map 更改相机位置。我知道如何更改相机位置,我已经编写了 NSLog 调用来测试我的应用程序在点击特定行时是否有响应,但我不知道如何连接这两个 Controller 。我考虑过让持有 mapview 的 Controller 成为 UITableView 的委托(delegate),但我对如何连接两者感到困惑。我有什么选择来进行这样的事情。

这就是我的 appdelegate 文件的样子。

...
mapviewController *mvc = [[mapViewController alloc]init];
locationTableController *ltc = [[locationTableController alloc]init];

UISplitViewController *svc = [[UISplitViewController alloc]init];
UINavigationController *sideNav = [[UINavigationController alloc]initWithRootViewController:ltc];
UINavigationController *mapNav = [[UINavigationController alloc]initWithRootViewController:mvc];
svc.delegate = mapNav;
svc.viewControllers = @[sideNav,mapNav];
....

最佳答案

我会将您的 locationTableController 保留为表的委托(delegate)和数据源。您可以使用 self.splitViewController 访问 splitViewController,您的 mapNav 位于 viewControllers[1] 并且您的 mapviewcontroller 是 mapNav 的 rootViewController。如果您在 mapviewcontroller 中实现了一个 changeCameraPosition 方法,您可以从 didSelectRowAtIndexPath 中调用它。所以在didSelectRowAtIndexPath中:

UISplitViewController *svc = self.splitViewController;
UINavigationController *mapNav = svc.viewControllers[1];
mapViewController *mvc = (mapViewController *)mapNav.rootViewController;
[mvc changeCameraPosition];

如果尚未导入,您可能需要导入相关的 .h 文件。就我个人而言,我会向 splitViewController 添加一些属性,以加快访问其他 View Controller 的速度。

关于ios - 将 didSelectRowAtIndexPath 与 UISplitViewController 和谷歌地图一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25942382/

相关文章:

ios - dyld`__abort_with_payload : Without an error message

ios - 如何在 UITableView 上添加额外的行分隔符

iphone - UITableView 的渐变背景

ios - MWFeedParser 删除嵌入的媒体 URL - iOS

ios - 自定义表格单元格重用/出队

ios - UITableView 删除行在 iOS 中崩溃

iphone - 为什么 popToRootViewContoller 要么卡住要么需要很长时间才能执行?

ios - 改变动画过渡

ios - 将带有可见导航栏的 View Controller 弹出到带有隐藏导航栏的 View Controller 时,带有 interactivePopGestureRecognizer 的黑色区域

iphone - iOS 电话中断后 AUGraph 停止运行