`
tudusi
  • 浏览: 1049246 次
文章分类
社区版块
存档分类
最新评论

xcode4.2 空项目如何加载view

 
阅读更多

这个是网上看到的一个论坛上的回答,希望对大家有所帮助,具体是哪的忘记了

“FYI, I am very newbie in iPhone development.”

I had upgraded Xcode to 4.2 beta 4 and realised that there is no more templates for iOS 4.
Obviously, it did not include iOS 4 SDK because it said “with iOS 5 SDK”, duh!
I could not go back to Xcode beta 3 since I upgraded my iPhone to beta 4 as well.

Anyway…

In the tutorial that I am learning at the moment, it requires “Window-based application”.
Xcode 4.2 beta 4 does not have “window-based application”; so, I created a project with “Empty application”.
Unfortunately, “Empty application” has no longer “MainWindow.xib”, which tutorial teacher said to modify something in it.
So, I googled to make “MainWindow.xib” visible and found this article.

“MainWindow.xib” posted by Jeroen Trappers

What he said is that “MainWindow.xib” is not included by default in templates. He suggested to create “MainWindow.xib” manually as below:
(FYI, this instruction is only for me. It is better to go to original article and follow.)

1. Create new project in Xcode 4.2 beta and choose “Empty Application” template
2. Add “New File” to the project by choosing “iOS -> User Interface -> Empty”
3. Choose “iPhone” and name “MainWindow” (.xib will be added automatically)

4. Open “MainWindow.xib” in project navigator
5. Click “File’s Owner” in “Placeholders”
Change Class as “UIApplication” in “Identity Inspector”
6. Drag “Object” in the library into “Objects” panel on the left
7. Change the class of the Object as your delegate class, such as “DemoAppDelegate”
(The name of object will be automatically change like “Demo App Delegate”)
8. Drag “Window” in the library into “Objects” panel on the left

9. Open “DemoAppDelegate.h” in project navigator
10. Find below code

@interface DemoAppDelegate :

UIResponder

@property (strong, nonatomic)UIWindow *window;

@end

11. Change as below:

@interface DemoAppDelegate :

UIResponder

@property (strong, nonatomic) IBOutlet UIWindow *window;

@end

11. Open “MainWindow.xib” in project navigator
12. Click “File’s Owner” in “Placeholders”
13. Control-Drag “delegate” of “Outlets” in “Connections Inspector” to “Demo App Delegate” in “Objects”
14. Click “Demo App Delgate” in “Objects”
15. Control-Drage “window” of “Outlets” in “Connections Inspector” to “Window” in “Objects”

16. Open “Summary” of your project
17. Find “iPhone / iPod Deployment Info”
18. Change “Main Interface” as “MainWindow”

19. Open “DemoAppDelegate.m” in project navigator
20. Find below code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

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

// Override point for customization after application launch.

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

return YES;

}

21. Change as below

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Override point for customization after application launch.

//self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

return YES;

}

在XCode4.2中添加MainWindow.xib文件

最近把XCode升级到了最新的4.2版本,然后在创建项目时,发现创建的Winzard改了,没有了以前的Window Based Application了,要创建一个干净点的项目该选用的模板是"Empty Project"。但是创建完之后,项目中不再有MainWindow.xib文件了,不过我们可以自己添加这个文件。

首先,选择添加文件,Cmd+N,然后选择 iOS->User Interface->Empty, Device选择iPhone, 把文件命名为MainWindow。

MainWindow

首先, 把File's Owner改为UIApplication.

UIApp

然后再从Library中, 添加一个Object,并把Object的Class改为你自己的AppDelegate。

delegate

再从Library中添加一个Window对象,

window.png

好了,需要的元素都齐了,最后需要把他们链接起来。

1. 把你的AppDelegate中的UIWindow标记为IBOutlet

2. 把MainWindow.xib的FileOwner的delegate设置为你的Demo App Delegate.

3. 把Window和你AppDelegate中的Outlet关联起来。

delegate

4. 把项目Summary属性下的Main Interface设置为MainWindow, 同时把appDidLaunchWithOptions中的UIWindow初始化代码删除。



分享到:
评论

相关推荐

    ios解决MainWindow教程源代码

    基于Xcode4.2解决Applications are expected to have a root view controller at the end of application launch 和建立MainWindow教程代码 对应图文教程: http://blog.csdn.net/abowu/article/details/7533026

    全面解析iOS应用中自定义UITableViewCell的方法

    1、运行Xcode 4.2,新建一个Single View Application,名称为Custom Cell: 2、将图片资源导入到工程。为此,我找了14张50×50的.png图片,名称依次是1、2、……、14,放在一个名为Images的文件夹中。将此

    Programming iOS 12 Dive Deep into Views View Controllers and Frameworks

    Stay up-to-date on iOS 12 innovations, such as User Notification framework improvements, as well as changes in Xcode 10 and Swift 4.2. All example code is available on GitHub for you to download, ...

    iOS5开发基础教程.pdf

    Every single sample program in the book has been rebuilt from scratch using Xcode 4.2 and the latest iOS 5-specific project templates and designed to take advantage of the latest Xcode features. ...

    InAppViewDebugger:一个UIView调试器(例如Reveal或Xcode),可以嵌入到应用程序中以进行设备上的视图调试

    可扩展:基本实现支持UIView层次结构,但这很容易扩展以支持任何类型的UI框架(例如CoreAnimation或SpriteKit)要求iOS 11.0以上Xcode 10.1+(为Swift 4.2构建的框架)安装可可豆Podfile添加到您的Podfile : pod '...

    iphone开发入门经典源码

    13.2 创建多视图选项卡栏应用程序 13.2.1 实现概述 13.2.2 创建项目 13.2.3 添加选项卡栏控制器 13.2.4 配置视图控制器类 13.2.5 实现ArcaView视图 13.2.6 实现VolumcView视图 13.2.7 实现SummaryView视图 ...

    material-showcase-ios::sparkles:在iOS应用程序中引导心爱的用户的一种优雅方法-Material Showcase

    您可以使用以下命令通过安装Carthage: $ brew update$ brew install carthage 要使用Carthage将MaterialShowcase集成到Xcode项目中,请在Cartfile指定它: github "aromajoin/material-showcase-ios" ~> 0.7.3运行...

    CircularRevealKit:循环显示动画变得容易

    您可以简单地使用此组件来显示和使ViewController / View变得不真实,该组件很小(大约40kb),仅使用Swift 5编写,并支持Swift 4.2。 样品 要求 Swift 4和iOS 9+ 安装 可可豆 是Cocoa项目的依赖项经理。 您可以...

    StackBarButtonItem::black_square_button:StackBarButtonItem可以使用StackView之类的BarButtonItem

    特征NavigationBar边距视图之间的间距反向视图支持设备:iPad |苹果手机方向:人像|风景多任务要求Xcode10或更高iOS9或更高Swift4.2或更高版本依存关系 (> = 4.3.1) (> = 4.3.1)安装迦太基如果您使用的是,只需...

    Programming iOS 12(pdf + epub)

    If you’re grounded in the basics of Swift, Xcode, and the Cocoa framework, this book provides a structured explanation of all essential real-world iOS app components. Through deep exploration and ...

    iphone3开发基础教程

    2.1 在Xcode中设置项目 8 2.2 Interface Builder简介 13 2.2.1 nib文件的构成 14 2.2.2 在视图中添加标签 15 2.3 美化iPhone应用程序 17 2.4 小结 20 第3章 处理基本交互 21 3.1 MVC范型 21 3.2 创建项目 22 3.3 ...

    IOS5 Programming Cookbook

    4.2 Adding a Navigation Controller to a Storyboard 333 4.3 Passing Data From One Screen to Another 346 4.4 Adding a Storyboard to an Existing Project 349 5. Concurrency . . . . . . . . . . . . . . . ....

    Sica:简单界面核心动画。 顺序或并行运行类型安全的动画

    产品特点具有持续时间和延迟的动画并行/序列动画缓和斯普林斯过渡要求Xcode 9.3或更高iOS 9或更高版本tvOS 10.0或更高macOS 10.11或更高版本Swift 4.2(自0.3.4起)安装迦太基如果您使用的是,只需将Sica添加到您的...

    iOS ARC 完全指南

    每次 Xcode编译项目吋,都会运行静态代码分析工具来检查我们的代码 Artists PROJECT Summary Info Build Settings Build Phases Build rules Art sts Basic (AlD(Cornbined Levels az static analyzer Setting h,Ais...

    科大讯飞的语音合成

    _iflyRecognizerView = [[IFlyRecognizerView alloc] initWithCenter:self.view.center]; _iflyRecognizerView.delegate = self; [_iflyRecognizerView setParameter: @"iat" forKey: [IFlySpeechConstant IFLY_...

Global site tag (gtag.js) - Google Analytics