开发者

navigation controller is null when pushing new view

开发者 https://www.devze.com 2023-04-05 06:02 出处:网络
I have a tab bar application and in one of those tabs I have a map view. I am trying to push a new view from clicking a disclosure button on an annotation on the map view using this code...

I have a tab bar application and in one of those tabs I have a map view. I am trying to push a new view from clicking a disclosure button on an annotation on the map view using this code...

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

childController = [[AnnotationDetailView alloc] initWithNibName:@"AnnotationDetailView" bundle:nil];       

[self.navigationController pushViewController:childController animated:YES];

}

however if I nslog the navigationController it is null.

What is confusing is that in another tab I have a table view which will push a view using the above code. Why does that work开发者_Python百科 but an map annotation doesn't.


The simple answer is that your table view is inside a navigation controller and your map view isn't. A tab view controller isn't actually a navigation controller itself.

Depending on your project, the fix may be as simple as editing your XIB so that a navigation controller is the immediate child of the tab controller for the map's tab, and the map view controller is the child of that navigation controller. Look at how your table view is defined, and you should be able to see what's different.


Have you defined childController as AnnotationDetailView * childController; in your header?

or you can simply use:

AnnotationDetailView * childController = [[AnnotationDetailView alloc] initWithNibName:@"AnnotationDetailView" bundle:nil];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号