storyboard

MRC 下编译 ARC 文件: 只将那两个文件ARC编译

单例:
  • 内存唯一
  • 只初始化一次, 永远不释放

Model层: 网络, 存储, 单例, 解析(XML, Jason), 数据 — 直观看上去都是一个类

如果打印的对象为nil, 则原因是没有进行初始化.
容器类型的变量(数组,集合, 字典), 如果在.h中声明了, 就必须在.m中对该容器进行初始化



这一页基本不动:





必须和类名一一匹配



file’s owner  — 类文件(MainViewController)


指向storyboard的箭头指的是window



storyboard作用: 视图控制器的切换


TableView:
1. 创建一个tableview
2. 拖cell
3. 放子视图
4. 给cell定义重用标识
5. 创建类cell
6. 关联子视图




关联类
创建类
连线


没有连线的切换用代码

StoryBoard:

建好项目之后删掉ViewController.h, ViewController.m和 Main.storyboard

新建文件MainViewController.h, MainViewController.m, 并且创建对应的.xlb文件:


在.xlb文件中, File’s Owner 对应的Class是MainViewController, 
拖拽Label, Button, 和 TextField到View上


在MainViewController.h文件中定义UILabel 类型和 UItextField 类型的属性以便与.xlb上的空间进行关联:
@property ( nonatomic , retain ) IBOutlet UILabel *showLabel;
@property ( nonatomic , retain ) IBOutlet UITextField *textField;
IBOutlet表示所标识的对象与外界.xlb文件进行关联

同样, 声明Button的点击事件方法(而不用声明UIButton对象作为属性):
- ( IBAction )buttonAction:( id )sender;
IBAction相当于 void

在.m中不全dealloc方法, 并实现点击事件:
- ( IBAction )buttonAction:( id )sender{
   
self . showLabel . text = self . textField . text ;
}

回到.xlb文件, 右键点击Label控件, 在出现的菜单中点击Referencing Outlet中的 New Referencing Outlet右边的加号, 并不放手, 拖拽到File’s Owner, 并松手, 在出现的菜单中点击showLabel, 即刚刚在.h中声明的属性


这样, 便使Label控件与showLabel对象关联起来了.

同样地, 使TextField控件与textField对象进行关联:



注意, 在File’s Owner 的关联关系中:



File’s Owner表示当前的类.
左侧表示的是类中的对象, 右侧表示的是.xib中的控件

RealStoryBoard:

真正的StoryBoard, 即工程刚创建好时系统自动创建的Main.storyboard 文件, 在此处对所有视图进行管理.

默认情况下, 刚创建好的工程中的Main.storyboard中以创建好与ViewController相关联的View Controller, 并与AppDelegate的window相关联了.
左侧的箭头即为window.



向storyboard中拖拽一个新的ViewController:



并创建一个SecondViewController, 继承与UIViewController:



重写 awakeFromNib方法:
- ( void )awakeFromNib{
    [
super awakeFromNib ];
}
类似于初始化方法, 只能用于storyboard的情况, 在viewDidLoad之前走.

注意不可以重写 loadView方法, 因为系统已经自动创建好了view.


使在storyboard中新建的View Controller与SecondViewController相关联:



分别将storyboard中的两个View Controller 设置颜色以便区分. 分别拖拽一个Button到两个View Controller上, Ctrl按住View Controller 上的 Button 到 Second View Controller上, 两个ViewController之间出现连线, 设置连线的Identifier为 detail:




在ViewController.m 和 SecondViewController.m 类的延展中声明UIButton属性及其点击事件:
@interface ViewController ()
- (IBAction)buttonAction:(id)sender;
@end


@interface SecondViewController ()
@property ( retain , nonatomic ) IBOutlet UIButton *button;
- ( IBAction )buttonAction:( id )sender;
@end

分别将Button拖拽到对应的代码上(按住Ctrl键拖拽Button到代码上):




系统同时会生成相应的dealloc方法和点击事件的实现框架.

在ViewController.m中添加如下方法:
- ( void )prepareForSegue:( UIStoryboardSegue *)segue sender:( id )sender{ // segue 指的是那条线 , sender 是那个 button
   
if ([segue. identifier isEqualToString : @"detail" ]) {
       
SecondViewController *secondViewController = ( SecondViewController *)segue. destinationViewController ;
        secondViewController.
name = @"Hello" ; // 把值传给将要进入页面的属性
    }
   
   
NSLog ( @"name = %@" , segue. identifier );
   
NSLog ( @"name = %@" , segue. sourceViewController );
   
NSLog ( @"name = %@" , segue. destinationViewController );
   
}
其中, segue指的是那条线, sender是Button
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值