简体   繁体   English

使用导航控制器从mapView推送详细视图

[英]Push a detail view from mapView with a Navigation Controller

I have a tabbed application with one of the tabs being a map view. 我有一个选项卡式应用程序,其中一个选项卡是地图视图。 The user places a pin in a location and in the annotation callout there is a disclosure button. 用户将图钉放在某个位置,并且在注释标注中有一个显示按钮。 I want this button to push to a detail view with more specific details about the annotation. 我希望此按钮可以推送到包含有关注释的更多特定详细信息的详细信息视图。 I have searched for related questions but none of them seem to have the same problem with it as I do. 我已经搜索了相关问题,但是似乎没有一个问题与我的问题相同。 When the disclosure button is clicked, the application crashes with the exception: 'NSInvalidArgumentException', reason: '-[MapView tableView]: unrecognized selector sent to instance 0x8434360' 单击公开按钮时,应用程序崩溃,但出现以下异常:'NSInvalidArgumentException',原因:'-[MapView tableView]:无法识别的选择器已发送到实例0x8434360'

This is where I attempt to push the detail view controller. 这是我尝试推送详细视图控制器的地方。 The log statement returns a navigation controller so it is not an issue of sending a message to nil. log语句返回导航控制器,因此将消息发送到nil并不是问题。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

{ {

DetailViewController *dvc = [[DetailViewController alloc] init];
NSLog(@"%@", [self navigationController]);
[[SpotsStore defaultStore] setSelectedSpot:[view annotation]];
[[self navigationController] pushViewController:dvc animated:YES];

} }

I instantiated the navigation controller in the app delegate: 我在应用程序委托中实例化了导航控制器:

UINavigationController *mapnc = [[UINavigationController alloc] initWithRootViewController:mv];
[mapnc setNavigationBarHidden:NO];
[[mapnc tabBarItem] setTitle:@"Map"];
[[mapnc tabBarItem] setImage:[UIImage imageNamed:@"mapicon.png"]];
[tbc setViewControllers:[NSArray arrayWithObjects:nc,mapnc, nil]];
// nc is a different navigation controller I instantiated earlier.
[[self window] setRootViewController:tbc];

I would really like any help with this, or just send me in the right direction. 我真的希望对此有任何帮助,或者只是向正确的方向发送。 I could not find anything about the navigation controller sending the method tableView. 我找不到有关发送方法tableView的导航控制器的任何信息。 Or why it doesn't work in this case. 还是为什么在这种情况下它不起作用。

I would stongly recommend using storyboards. 我强烈建议使用情节提要。 Create a tabbarcontroller. 创建一个tabbarcontroller。 Create a navigationcontroller with 2 viewcontrollers: the first is the map iewcontroller, the second is the detailviewcontroller. 创建一个具有2个视图控制器的Navigationcontroller:第一个是地图iewcontroller,第二个是detailviewcontroller。 Ste this navigationcontroller to be one of the tabbarcontrollers viewcontrollers. 将此导航控制器设为TabbarControllers视图控制器之一。 In your calloutaccessorytapped method call performSegue with the identifier that you defined in the storyboatd. 在您的calloutaccessorytapped方法中,使用您在Storyboatd中定义的标识符调用performSegue。

I found the problem. 我发现了问题。 It was a piece of code in my detail view viewWillAppear method in which i reloaded the tableView. 这是我的详细视图viewWillAppear方法中的一段代码,在其中我重新加载了tableView。 Thanks for your help though! 谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将视图控制器从根目录推送到详细信息视图控制器(SplitView) - Push a view controller from root to detail view controller (SplitView) 如何从详细视图 controller 以编程方式推送视图 controller - How to push a view controller programmatically from Detail view controller 如何将字幕从uitableview推送到详细视图控制器 - how to push subtitle from uitableview to detail view controller 导航控制器推送视图控制器 - Navigation Controller Push View Controller 如何从主视图控制器在详细视图控制器中推送新视图? - How to push new view in detail view controller from master view controller? 从滚动视图(子视图)内部将视图推送到导航控制器 - Push a View to a Navigation Controller from inside a scroll view (subview) 推送/弹出视图控制器,带有导航栏,来自View Controller,不带导航栏 - Push / Pop View Controller With Navigation Bar from View Controller Without Navigation Bar 显示带导航的地图视图?.push(mapView) 并没有看到任何弹出 - Displaying map view with navigation?.push(mapView) and not seeing anything pop up 如何通过推送通知使用TabBarController导航显示视图控制器 - How to show view controller with TabBarController navigation from push notification 通过推送通知使用导航控制器打开特定视图 - Opening specific view with navigation controller from push notication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM