IOS基础学习(1)---Storyboard与xib跳转

来源:互联网 发布:三星m3325nd网络打印 编辑:程序博客网 时间:2024/06/04 20:04

 Storyboard是XCode4.2才开始支持的,为了使设计View更容易。相对于Xib,更适合初学者,基本上只要在storyboard界面就可以完成一切,尤其是 View导航,可以不编写一行代码就可以搞定。

本文主要对比Storyboard和Xib的导航,也就是单击当前View的一个Button,会跳到另外一个TableView上.

1、首先新建一个工程,删除默认生成的 View Controller,添加一个Navigation Controller到视图上。然后再添加一个Tablev Viewc Controller。



2、将View Controller设置为Rootview,


3、将Tableview Controller的Storyboard ID设置为FristController,


4、新建一个文件,命名为FristController,将tableview Contentroller与其关联起来,



5、添加一个Button到view上,修改title为“Sign in,并为按钮添加点击事件,



5、在ViewController.m中,导入头文件并引入tableview:

#import "FristController.h"@interface ViewController ()@property (nonatomic, strong) FristController *fristController;@end
6、在Button的函数下添加跳转的代码:

- (IBAction)ReturnFrist:(id)sender{    self.fristController=[[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]instantiateViewControllerWithIdentifier:@"FristController"];    [self.navigationController pushViewController:self.fristController animated:YES];}
7、运行Demo ,查看效果。



8、下面开始xib 的跳转,注释掉
ReturnFrist方法下的代码:添加一个名为FristTableViewController的TableViewController,


9、导入头文件并引入:

#import "FristTableViewController.h"
@property (nonatomic ,strong) FristTableViewController *fristTableViewController;
10、在ReturnFrist方法下添加实现跳转代码:

self.fristTableViewController=[[FristTableViewController alloc]initWithNibName:@"FristTableViewController" bundle:nil];    [self presentViewController:self.fristTableViewController                       animated:YES                     completion:^{                     }];


demo下载请戳:http://download.csdn.net/detail/ningshuang520/8036279

0 0
原创粉丝点击