开发者

Setting up a Navigation Controller with a Map View in Interface Builder

I'm trying to create a modal view which pops up when the user presses a button. The modal view has a navigation bar with a map view as the main view. I'm having trouble setting this up in Interface Builder. When I set the view outlet for my File's Owner's view to the view inside the Navigation Controller, the only thing that show up is the map view, with a grey space at the top and bottom. The navigation bar never appears. Here's a screenshop o开发者_开发技巧f how it looks, with an image of my IB window.

How can I get the navigation bar to show up properly? Thanks

alt text http://img.skitch.com/20100126-d5u4yuufpe77xdkuw2k1h9uahf.jpg

http://img.skitch.com/20100126-xrw6qd5jajytkq5u7x3kdk168s.jpg http://img.skitch.com/20100126-xrw6qd5jajytkq5u7x3kdk168s.jpg

Just in case, here's the MapViewController declaration:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface MapViewController : UIViewController
{}
@end

And the code to push the modal view controller:

MapViewController *mapVC = [[MapViewController alloc] init];
self.mapViewController = mapVC;
[mapVC release];
[self presentModalViewController:mapViewController animated:YES];



You are going about this the wrong way in your NIB file.

Add the MKMapView to the view of the UIViewController. You could add a navigation bar here instead of a controller if you don't wish this view to go anywhere else.

However, having the navigation controller is very handy. So, ensure that there is no navigation controller in the NIB file for your MapViewController class and then edit your code to look like this:


MapViewController *mapVC = [[MapViewController alloc] init];
self.mapViewController = mapVC;
[mapVC release];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mapViewController];
[self presentModalViewController:navController animated:YES];
[navController release];

Then you can access this controller from within your MapViewController.m file by using:

self.navigationController
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜