【发布时间】:2010-10-13 01:23:38
【问题描述】:
我正在尝试通过基本的 iPhone 编程来工作,并且我对 Interface Builder 的工作原理有很好的基本了解,因此我决定尝试以编程方式编写视图。我浏览了 ViewController Apple 指南并到处搜索,但似乎找不到解决问题的方法。这让我相信这是一个非常简单的解决方案,但我只是真的把头撞在墙上。基本上我要做的就是创建一个将主窗口作为子视图的视图。我知道如果 self.view 没有定义,那么应该调用 loadView 方法,并且应该在那里设置一切。这是我的代码的当前状态:
委托人:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
StartMenuViewController *aViewController = [[StartMenuViewController alloc] init];
self.myViewController = aViewController;
[aViewController release];
UIView *controllersView = [myViewController view];
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window setBackgroundColor:[UIColor redColor]];
[window addSubview:controllersView];
[window makeKeyAndVisible];
}
视图控制器:
- (id)init {
if (self = [super init]) {
self.title = @"Start Menu";
}
return self;
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
UIView *startView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[startView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[startView setBackgroundColor:[UIColor greenColor]];
self.view = startView;
[startView release];
}
提前感谢您的帮助!
【问题讨论】:
标签: cocoa-touch