zoukankan      html  css  js  c++  java
  • xcode 学习笔记4:给WindowBase程序添加view

    1:新建一个基于windowbase的程序。你会发现它只有一个MainWindow.xib,打开这个文件,拖拽一个View Controller控件到下图的MainWindow.xib窗口。

    2:右键单击Classes文件夹,为项目添加新的文件。如下图:

    选择文件类型为Cocoa Touch Class,注意勾选上Targeted for iPad以及With XIB for user interface(产生xib文件)

    点击确定并给类起个名字,我起的是TestViewController,回到工程会发现多了3个文件:TestViewController.h, TestViewController.m,TestViewController.xib

    最好将这个xib文件拖入到Resources文件夹里。

    3:双击在interface builder中打开MainWindow.xib,在右侧的悬浮窗口里面的最上面的3个标签,分别选中第一个标签(属性标签)并在nib name那一栏点击三角图标在弹出的选项中选择TestViewController,这样就将MainWindow.xib和TestViewController.xib关联起来了。再选择第4个标签(ID标签)并点击Class的三角图标在弹出的类里面选中TestViewController,这样就将TestViewController.xib和TestViewController类关联起来了。

    4:在XXXAppDelegate.h中添加如下代码,蓝色字体为新增代码

    #import <UIKit/UIKit.h>

    @class TestViewController;

    @interface WindowBaseTestAppDelegate : NSObject <UIApplicationDelegate> {
        UIWindow *window;
        TestViewController *viewController;
    }

    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet TestViewController *viewController;

    @end

    在XXXAppDelegate.m中添加如下代码,

    #import "WindowBaseTestAppDelegate.h"
    #import "TestViewController.h"

    @implementation WindowBaseTestAppDelegate

    @synthesize window;
    @synthesize viewController;


    #pragma mark -
    #pragma mark Application lifecycle

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
       
        // Override point for customization after application launch.
        [window addSubview:viewController.view];
       
        [self.window makeKeyAndVisible];
       
        return YES;
    }

    ...

    - (void)dealloc {
       [viewController release];
        [window release];
        [super dealloc];
    }

    5:打开MainWindow.xib文件,鼠标左键单击Window Base ..之后鼠标右键按住它拖拽到View Con..在弹出的窗口中选中viewController,保存之。

    到这里算是大功告成了。ps:为了使得效果明显一点,你最好给TestViewController.xib文件添加一个控件什么的。

  • 相关阅读:
    二十八、线程安全
    一、JAVA内存区域与内存溢出异常
    一、SQLite学习
    排列问题
    2016年秋季个人阅读计划
    有向图强连通分量求解【转】
    《梦断代码》阅读笔记之五
    《梦断代码》阅读笔记之四
    软件工程个人总结
    《梦断代码》阅读笔记之三
  • 原文地址:https://www.cnblogs.com/sola/p/2023101.html
Copyright © 2011-2022 走看看