我正在尝试创建一个使用 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