码迷,mamicode.com
首页 > 其他好文 > 详细

XIB可视化编程

时间:2016-03-04 22:23:18      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:

1.xib可视化编程只提供一个UI界面,创建新的类的时候勾选生成xib文件,就会生成对应的xib文件,xib

GUI:图形?用户界?面(Graphical User Interface,简称 GUI,?又称图形?用户接?口)是指采?用图形?方式显?示的计算机操作?用户界?面。

Interface Builder(简称IB):是Mac OS X平台下?用于设计和测试图形?用户界?面(GUI)的应?用程序。代码和IB都可以?成GUI。

优势:IB能够使开发者简单快捷的开发出符合Mac系列操作系统的GUI。通常你只需要通过简单的拖拽操作来构建GUI就可以了。IB使?用Nib?文件储存GUI资源,在需要的时候,Nib?文件可以被快速地载?入内存。

2.iOS下可视化编程分为两种?方式:xib和storyBoard在使用xib和storyBoard创建GUI过程中,以XML文件格式存储在Xcode中,编译时?生成nib的?二进制?文件。在运?行时,nib?文件被加载并且开始创建和实例化GUI元素

3.xib与storyBoard的不同点:1.xib只有一个UI界面,storyBoard可以添加多个ViewController,2.xib上添加的控件设置代理的时候可以直接把控件直接拖向fiel‘s Owner直接点击代理即可,storyBoard必须用代码的方式设置代理,3.xib与之对应的viewController相关联,而storyBoard必须新建与之对应的viewController并设置关联才可以

 

使用xib自定cell

 1 #import "FirstTableViewController.h"
 2 #import "FirstTableViewCell.h"
 3 //苹果推崇的一种标识方式,const是不可修改
 4 static NSString *const idetifier = @"cell";
 5 @interface FirstTableViewController ()
 6 
 7 @end
 8 
 9 @implementation FirstTableViewController
10 
11 - (void)viewDidLoad {
12     [super viewDidLoad];
13     //注册cell[xib注册cell的方式](在文件中找寻有没有相对应的xib)
14     [self.tableView registerNib:[UINib nibWithNibName:@"FirstTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:idetifier];
15     
16 }
17 
18 - (void)didReceiveMemoryWarning {
19     [super didReceiveMemoryWarning];
20     // Dispose of any resources that can be recreated.
21 }
22 
23 #pragma mark - Table view data source
24 
25 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
26 #warning Incomplete implementation, return the number of sections
27     return 1;
28 }
29 
30 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
31 #warning Incomplete implementation, return the number of rows
32     return 2;
33 }
34 
35 
36 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
37     //使用可视化编程自定义cell的时候不能删除indexPath
38     FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idetifier forIndexPath:indexPath];
39 //    if (cell == nil) {
40 //        cell = [[FirstTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idetifier];
41 //    }
42 //第二种方式注册不能运行   
43     
44     
45     return cell;
46 }
47 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
48 {
49     return 200;
50 }

技术分享

xib中标识必须和注册的时候保持一致

自动布局中必须给控件添加四个约束才可以

 

XIB可视化编程

标签:

原文地址:http://www.cnblogs.com/DevinSMR/p/5243457.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!