应用程序启动时加载视图
我想创建一个只有一个视图的应用程序(TestViewController.h TestViewController.m)。 (没有标签栏,没有导航栏)不知道为什么在我启动应用程序后,屏幕完全黑了。看来应用程序没有成功加载视图?因为如果加载视图,屏幕应该是白色的。我说得对还是不对?
这是 AppDelegate.h
#import <UIKit/UIKit.h>
@class TestViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow *window;
TestViewController *testrViewController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TestViewController *testViewController;
@end
这是 AppDelegate.m
#import "AppDelegate.h"
#import "TestViewController.h"
@implementation AppDelegate
@synthesize window = window;
@synthesize testViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window addSubview:testViewController.view];
[self.window makeKeyAndVisible];
return YES;
}
I want to create a app with only one view(TestViewController.h TestViewController.m). (no Tabbar, no Navigation Bar) Don't know why after i launch the app, the screen is totally black. It seems that the app did not load the view successfully? Since if the view is loaded, the screen should be white. Am I right or not?
Here's AppDelegate.h
#import <UIKit/UIKit.h>
@class TestViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow *window;
TestViewController *testrViewController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) TestViewController *testViewController;
@end
Here's AppDelegate.m
#import "AppDelegate.h"
#import "TestViewController.h"
@implementation AppDelegate
@synthesize window = window;
@synthesize testViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window addSubview:testViewController.view];
[self.window makeKeyAndVisible];
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我看来,你并没有开设课程
希望它有帮助
It seems to me that you're not instatiating the class
Hope it helps
如果您以编程方式创建它,那么您还应该实例化
window
然后实例化 ViewController
,然后使其可见
if you are creating it programmatically, then you should also instantiate
window
then your ViewController
and then make it visible
您是否为 testViewController 创建了 .xib?如果没有,那么您必须在 testViewController 上添加一个子视图。然后尝试。我希望它会起作用。
did you create .xib for testViewController. If not then you have to add a subview over your testViewController. and then try. I hope it will work.