[英]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.