1

我正在尝试创建一个使用 iPhone MapView(在 Google 代码下)的应用程序。我不知道如何在不手写整个 UI 的情况下将这个东西集成到我的应用程序中,即根本不使用 IB。

如何使用界面生成器来创建我的所有菜单等,但添加 MapView?我是否需要编辑 MapView 以使其成为 IB 组件?

谢谢!

编辑:

@pgb

这是我的代码,它仍然只显示一个空白的 UIView,我已经在 IB 端连接了所有东西。

//
//  NewTestViewController.h
//  NewTest
//

#import <UIKit/UIKit.h>

@interface NewTestViewController : UIViewController {
 UIView* mapPlaceholder;

}
@property (nonatomic, retain) IBOutlet UIView* mapPlaceholder;
@end

//
//  NewTestViewController.m
//  NewTest
//

#import "NewTestViewController.h"
#import "MapView.h"

@implementation NewTestViewController
@synthesize mapPlaceholder;



// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        MapView *mapView = [[[MapView alloc] initWithFrame:
        [[UIScreen mainScreen] applicationFrame]] autorelease];
  [mapPlaceholder addSubview:mapView];
    }
    return self;
}


/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}


- (void)dealloc {
 [mapPlaceholder.subviews release];
    [super dealloc];
}

@end

没关系想通它比 PBG

4

3 回答 3

2

您可能可以在 IB 中创建整个界面,添加一个空白UIView作为占位符视图,然后使用addSubview:MapView实例添加到视图层次结构中。

您的占位符视图可以定义为IBOutlet,因此您可以MapView从您的UIViewController实例中添加 。

于 2009-09-14T23:34:13.860 回答
1

在 IB 中,您可以添加一个 UIView,然后将视图的类型更改为任何自定义 UIView - 我假设 MapView 子类 UIView 就像 MKMapView 一样...

于 2009-09-15T15:44:05.373 回答
0

我正在尝试创建一个使用 iPhone MapView(在 Google 代码下)的应用程序。

为什么不使用 MapKit?当然,IB 在其库中带有一个 MKMapView。

于 2009-09-14T23:16:55.723 回答