在空模板中查看

发布于 2024-12-04 01:58:51 字数 62 浏览 1 评论 0原文

我需要在空模板上使用控制器创建自己的视图,而无需界面生成器的帮助。我需要在 AppDelegate 中写什么?

I need to create my own view with controller on empty template without help of Interface Builder. What i need to write in AppDelegate ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2024-12-11 01:58:51

XCode->新项目->选择基于窗口的模板。然后从资源中删除 MainWindow.xib,从 info.plist 中删除此键“Main Nib file base name”。在您的 main.m 文件中
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate"); // 第四个参数是您的 AppDelegate 的名称。在您的 AppDelegate.h 中删除 IBOutlet UIWindow 的属性/合成,因为您根本不使用 IB。

// In your AppDelegate.m    
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [window makeKeyAndVisible];

            // In your AppDelegate.h AnotherViewController* mainViewController;
            mainViewController = [[AnotherViewController alloc] init];
            [[mainViewController view] setFrame:[UIScreen mainScreen].applicationFrame];
            [window addSubView:[mainViewController view]];
    }

// In your AnotherViewController implement 
- (void)loadView
{
  // Lets say you have a UITableView
  UITableView* tableView = [[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain] autorelease];
  [self setView:tableView];
}

XCode -> New project -> Select Window Based Template. Then Remove MainWindow.xib from resources, from info.plist remove this key "Main Nib file base name".In your main.m file
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate"); // 4th parameter is name of your AppDelegate. In your AppDelegate.h remove property/synthesize for your IBOutlet UIWindow as you are not using IB at all..

// In your AppDelegate.m    
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [window makeKeyAndVisible];

            // In your AppDelegate.h AnotherViewController* mainViewController;
            mainViewController = [[AnotherViewController alloc] init];
            [[mainViewController view] setFrame:[UIScreen mainScreen].applicationFrame];
            [window addSubView:[mainViewController view]];
    }

// In your AnotherViewController implement 
- (void)loadView
{
  // Lets say you have a UITableView
  UITableView* tableView = [[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain] autorelease];
  [self setView:tableView];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文