您的位置:首页 > 编程语言

Xcode-学会使用代码块提高你的开发效率

2017-03-28 13:45 363 查看

前言

我们在开发的过程中很多代码我们需要重复写很多遍,所以我们写代码经常被称作搬砖的,也就是重复着做同样的事,只是不同的UI界面罢了,什么设计模式啊、数据结构啊、数据解析啊and so on...都一样。我们怎么来提高我们的开发效率呢???我相信大家很多都是把一些通用的东西封装起来,然后在不同的地方调用,我们开发做久了,就会发现我们写软件,其实很简单,就是组装了;但是有些代码我们不能通过封装来解决,还有什么简单的除了copy以外的方法呢???这就是本文的重点了,代码块!!!
使用演示





使用教程

上面看着简单吧,但是怎么弄的呢???带我慢慢道来!
1.先写好我们需要做代码块的代码,如下:
#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return <#expression#>
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = <#(nonnull NSString *)#>;
<#classCell#> *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if(cell==nil){
cell = [[<#classCell#> alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return <#expression#>
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}2.将我们写好的代码块拖入右下角的代码块模块,如下图:



3.给我们代码块命名





Completion Shortcut 就是我设置MyCode
Title 就是我设置 Tableview 和 TableViewDelegate
3.修改代码块



4.删除代码块
选中代码块,直接敲击键盘上的Delect就好。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐