ios storyboard的入门

0、如何让storyboard的ViewController控件绑定代码的ViewController

1
2
在storyboard里面创建了一个ViewController后,要在代码那边创建一个
自定义Controller去继承UIViewController,然后在storyboard里面选择对应的custom class为自定义Controller,就可以完成关联

1、如何让storyboard与代码进行事件交互。

1
2
3
在storyboard里拉出一个label和一个button,然后屏幕调出来两个界面,一个storyboard,一个controller的代码框
选中storyboard里的label,右键按住,拉到代码框的@interface @end中间,就会出现label的定义
选中storyboard里的button,右键按住,拉到代码框的@implementation @end中间,就会出现button的事件定义

1、出现Launch screens may not set custom classnames问题

1
2
图中所画的不要打勾
![](http://pd4ketimy.bkt.clouddn.com/15394960479910.jpg)

4、如何设定storyboard的入口

1
2
storyboradviewController里面设置,如下图,红色那个选项打勾
![](http://pd4ketimy.bkt.clouddn.com/15394966538273.jpg)

5、多个storyBoard,怎么设置特定的storyBoard

1
项目->info.plist->Main storyboard file base name 设置为指定的storyBoard即可

6、使用storyBoard生成viewController,关联viewController后,代码pushViewController 黑屏

1
2
3
4
5
6
7
8
SecondController *controller = [[SecondController alloc]init];
[self.navigationController pushViewController:controller animated:YES];

使用storyBoard创建的时候已经有了一个viewController实例,不应该在代码里再alloc init另外一个controller,解决方案就是要去storyBoard里面把viewController拿出来

UIStoryboard *main =[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
SecondController *b = [main instantiateViewControllerWithIdentifier:@"SecondController"];
[self.navigationController pushViewController:b animated:YES];

7、回调的使用,
block
定义typeof
方法里面写

8、cocopad的安装使用

9、当改用cocoapods来管理依赖,
编译的时候提示 “ objc ld: library not found for -lPods”
这是因为打开的方式不对
之前打开的是.xcodeproj
用cocoapods后打开的是.xcworkspace

target -> Build Phases -> Link Binary With Libraries -> 添加.a文件

10、数据库fmdb->orm

11、UITable的使用

12、storyboard使用xib的自定义view
新建一个.h .m文件叫ItemView
新建一个.xib文件叫ItemView
在xib文件里,设置view customView为空 设置file’s Owner的custionView为ItemView
storyboard里拖出一个UIview,custom class指向ItemView
在ItemView.m里添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@property (strong, nonatomic) UIView *view;

// 初始化CustomView的时候添加xib上的view
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self){
[self addSubview:self.view];
}
return self;
}
// 获取xib中的view
- (UIView *)view{
if (!_view) {
_view = [[NSBundle mainBundle] loadNibNamed:@"ItemView" owner:self options:nil].lastObject;
}
return _view;
}

- (void)layoutSubviews{
[super layoutSubviews];
//设置大小
self.view.frame = self.bounds;
}

13、给非UiButton的控件加点击事件

1
2
3
4
5
6
7
8
[_mIBSetDeviceTime setUserInteractionEnabled:YES];
[_mIBSetDeviceTime addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickCategory:)]];

-(void)clickCategory:(UITapGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer view] == _mIBSetDeviceTime) {
NSLog(@"_mIBSetDeviceTime");//判断是哪个控件的点击
}
}

14、fragment如果要使用kotlin的 apply plugin: ‘kotlin-android-extensions’

那么必须放在onActivityCreated后才能生效
onCreateView里面的是为空的