http://www.mamicode.com/info-detail-514151.html

由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载原理很重要,所以,需要创建一个没有storyboard的项目

1. 创建一个新的工程

2. 选择仅一个视图的模板

选择 Single View Application , 点击Next

3. 填写项目信息

不需要选择core data,填好信息后,点击next,然后点击create

4. 删除storyboard和launchscreen.xib文件

将storyboard和launchscreen扔进废纸篓

5. 修改info.plist文件

删除info.plist文件中Main storyboard file base name和Launch screen interface file base name两个属性

6. 创建user interface的视图xib文件

点击next,然后Save as “HelloWorldView”点击Create

从object library中拖出一个Lable,再拖出一个button形成下面图即可

7. 修改视图控制器文件

创建视图和控制器的关联,Xcode默认创建了ViewController.h和ViewController.m文件,所以就不用自己创建了

1)修改xib视图文件的File‘s Owner

点击列表中的File‘s Owner,按command+option+3 打开 Identity Inspector,修改Custom Class中的Class为ViewController

2)创建输出口和动作方法的关联

点击中间的两个圈,打开辅助编辑器

选定Lable视图同时按住control键拖到ViewController.h的@interface与@end中间会弹出菜单,按照下图填写内容,然后回车创建输出口

创建button的动作方法也是选定视图并按住controll键拖到辅助编辑区

创建好关联后,ViewController.h的代码变为:

1 #import <UIKit/UIKit.h>
2
3 @interface ViewController : UIViewController
4 @property (weak, nonatomic) IBOutlet UILabel *helloLable;
5 - (IBAction)helloButton:(UIButton *)sender;
6
7 @end

点击xib列表中的File‘s Owner,然后按command+option+6 打开Connection Inspector查看输出口和动作的关联,将View与ViewController从UIViewController中继承的view属性进行关联

关联好的连接检查器如下所示

3) 修改ViewController.m的代码

 1 #import "ViewController.h"
2
3 @interface ViewController ()
4
5 @end
6
7 @implementation ViewController
8
9 - (void)viewDidLoad {
10 [super viewDidLoad];
11 // Do any additional setup after loading the view, typically from a nib.
12
13 }
14
15 - (void)didReceiveMemoryWarning {
16 [super didReceiveMemoryWarning];
17 // Dispose of any resources that can be recreated.
18 }
19
20 - (IBAction)helloButton:(UIButton *)senhder {
21 self.helloLable.frame = CGRectMake(10, 50, 300, 40);
22 self.helloLable.text = @"Hello World!";
23 }
24 @end

8. 修改AppDelegate.m 文件

在Xcode默认创建的AppDelegate.h文件中已存在以下代码:

1 #import <UIKit/UIKit.h>
2
3 @interface AppDelegate : UIResponder <UIApplicationDelegate>
4
5 @property (strong, nonatomic) UIWindow *window;
6
7 @end

Xcode默认为应用委托创建了window的属性,打开AppDlegate.m文件,引入ViewController.h

重写AppDlegate.m文件的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法

其他代码不作修改,代码如下

 1 #import "AppDelegate.h"
2 #import "ViewController.h"
3 @interface AppDelegate ()
4
5 @end
6
7 @implementation AppDelegate
8
9
10 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
11 // Override point for customization after application launch.
12 //创建window
13 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
14 //创建ViewController实例
15 ViewController *viewController = [[ViewController alloc] initWithNibName:@"HelloWorldView" bundle:nil];
16 //设置window根视图控制器
17 self.window.rootViewController = viewController;
18 self.window.backgroundColor = [UIColor whiteColor];
19 [self.window makeKeyAndVisible];
20 return YES;
21 }

9. 运行程序

command+R

初学iOS很多内容不正确的,请批评指出,谢谢

iOS学习笔记(2)--Xcode6.1创建仅xib文件无storyboard的hello world应用的更多相关文章

  1. [转]iOS学习笔记(2)--Xcode6.1创建仅xib文件无storyboard的hello world应用

    转载地址:http://www.mamicode.com/info-detail-514151.html 由于Xcode6之后,默认创建storyboard而非xib文件,而作为初学,了解xib的加载 ...

  2. Linux内核学习笔记之seq_file接口创建可读写proc文件

    转自:http://blog.csdn.net/mumufan05/article/details/45803219 学习笔记与个人理解,如有错误,欢迎指正. 温馨提示:建议跟着注释中的编号顺序阅读代 ...

  3. iOS学习笔记-精华整理

    iOS学习笔记总结整理 一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始 ...

  4. iOS学习笔记总结整理

    来源:http://mobile.51cto.com/iphone-386851_all.htm 学习IOS开发这对于一个初学者来说,是一件非常挠头的事情.其实学习IOS开发无外乎平时的积累与总结.下 ...

  5. IOS学习笔记48--一些常见的IOS知识点+面试题

      IOS学习笔记48--一些常见的IOS知识点+面试题   1.堆和栈什么区别? 答:管理方式:对于栈来讲,是由编译器自动管理,无需我们手工控制:对于堆来说,释放工作由程序员控制,容易产生memor ...

  6. iOS学习笔记10-UIView动画

    上次学习了iOS学习笔记09-核心动画CoreAnimation,这次继续学习动画,上次使用的CoreAnimation很多人感觉使用起来很繁琐,有没有更加方便的动画效果实现呢?答案是有的,那就是UI ...

  7. iOS学习笔记之Category

    iOS学习笔记之Category 写在前面 Category是类别(也称为类目或范畴),使用Category,程序员可以为任何已有的类添加方法.使用类别可以对框架提供的类(无法获取源码,不能直接修改) ...

  8. iOS学习笔记之ARC内存管理

    iOS学习笔记之ARC内存管理 写在前面 ARC(Automatic Reference Counting),自动引用计数,是iOS中采用的一种内存管理方式. 指针变量与对象所有权 指针变量暗含了对其 ...

  9. IOS学习笔记(四)之UITextField和UITextView控件学习

    IOS学习笔记(四)之UITextField和UITextView控件学习(博客地址:http://blog.csdn.net/developer_jiangqq) Author:hmjiangqq ...

随机推荐

  1. 升级10.11.6后CocoaPods的坑,之前10.11.4已经安装好的,居然没了Failed to locate Homebrew!

    升级10.11.6后CocoaPods的坑,之前10.11.4已经安装好的,居然没了,用命令 sudo gem install cocoapod 装不上,换 sudo gem install -n/u ...

  2. VS插件开发,启用实验室环境

    启用外部程序: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe 命令行参数 /rootsuffix ...

  3. JAVA利用Zip4j解压缩【转】

    官方地址:http://www.lingala.net/zip4j/(需要FQ) jar包:http://pan.baidu.com/s/145hwI 演示包:http://pan.baidu.com ...

  4. linux命令--dig

    dig,和nslookup作用有些类似,都是DNS查询工具,但是却比nslookup强大 dig,其实是一个缩写,即Domain Information Groper. [我想用google-DNS来 ...

  5. SQl语句学习笔记(二)

    merge into        when matched then...  when not mached then... merge into t_road_pre_parameter a fr ...

  6. 2015年11月26日 Java基础系列(六)正则表达式Regex

    package com.demo.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @autho ...

  7. [译]git reflog

    用法 git reflog 显示整个本地仓储的commit, 包括所有branch的commit, 甚至包括已经撤销的commit, 只要HEAD发生了变化, 就会在reflog里面看得到. git ...

  8. #define 中#和##的作用

    #的作用是把后面的参数变成一个字符串. 如,#define f(a) #a f(hello world)相当于"hello world": ##的作用是把两个字符串连接起来. 如, ...

  9. HDOJ 4336 Card Collector

    容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  10. 论在Windows下远程连接Ubuntu

       Ubuntu下1:下载xrdp   sudo apt-get install xrdp 2: urs/share/applications 下找到  远程桌面 设置成这样 Windows下 1; ...