iOS ViewController 中代码书写规范
示例:
//
// CommonViewController.m
// ZTBCamera
//
// Created by ZachRobin on 2017/8/3.
// Copyright © 2017年 Dreams of Ideal World Co.,Ltd. All rights reserved.
// static const CGFloat customValue = ; //定义静态变量 #define kScreenWidth [[UIScreen mainScreen] bounds].size.width //定义 #import "CommonViewController.h" #import "MagnumOpusCell.h" //引入头文件
#import "MagnumOpusDetailViewController.h" @interface CommonViewController () <UITableViewDelegate, UITableViewDataSource, MagnumOpusCellDelegate>
{
NSString *varableStr;//定义变量
} @property (nonatomic, strong) UITableView *contentTableView; @end @implementation CommonViewController #pragma mark - ViewController Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(, , , );
[button setTitle:@"按钮" forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor redColor]];
[button addTarget:self action:@selector(buttonDidClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
} - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
} - (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
} - (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
} #pragma mark - System Delegate --
#pragma mark - UITableViewDelegate / UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;//_contentArray.count
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MagnumOpusCell *cell=[self.contentTableView dequeueReusableCellWithIdentifier:@"IDMagnumOpusCell"];
if (!cell) {
cell = [[MagnumOpusCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"IDMagnumOpusCell"];
}
[cell buildCellWithItem:nil];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
MagnumOpusCell *cell = (MagnumOpusCell *)[self tableView:self.contentTableView cellForRowAtIndexPath:indexPath];
return [cell getCellHeight];
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"当前选中了 %ld", indexPath.row);
MagnumOpusDetailViewController *VC = [[MagnumOpusDetailViewController alloc] init];
[self.navigationController pushViewController:VC animated:YES];
} #pragma mark - Customer Delegate
- (void)removeCurrentCellData:(id)index
{ } #pragma mark - Event Response
- (void)buttonDidClick:(id)sender
{
[self requestData];
} #pragma mark - Private Method
- (void)requestData
{ } #pragma mark - Getters / Setters
- (UITableView *)contentTableView
{
if (!_contentTableView) {
_contentTableView = [[UITableView alloc] initWithFrame:CGRectMake(, , self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
_contentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_contentTableView.showsVerticalScrollIndicator = NO;
_contentTableView.delegate = self;
_contentTableView.dataSource = self;
UINib *nib = [UINib nibWithNibName:@"MagnumOpusCell" bundle:[NSBundle mainBundle]];
_contentTableView.backgroundColor = [UIColor clearColor];
_contentTableView.showsVerticalScrollIndicator = NO;
[_contentTableView registerNib:nib forCellReuseIdentifier:@"IDMagnumOpusCell"];
}
return _contentTableView;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
附件:示例代码。
iOS ViewController 中代码书写规范的更多相关文章
- WEB标准:标准定义、好处、名词解释、常用术语、命名习惯、浏览器兼容、代码书写规范
1. WEB标准是什么? “WEB标准”是一系列标准的总称.一般的误区经常把WEB标准说成DIV+CSS.准确的说法应该是:采用W3C推荐的WEB标准中的XHTML1.1结合CSS2.0 样式表制作页 ...
- C#中的代码书写规范以及命名规范
C#代码书写规则: 1. 尽量使用接口,然后使用类实现接口,以提高程序的灵活性. 2.一行不要超过80个字符 3.尽量不要手动更改计算机生成的代码 4.关键的语句写注释 5.建议局部变量在最接近使用它 ...
- (转)Java代码书写规范
0. 安装阿里代码规范的eclipse插件 https://www.cnblogs.com/caer/p/7753522.html 1.基本原则 强制性原则: 1.字符串的拼加操作,必须使用S ...
- Unity项目代码书写规范
以Google的代码规范为主,稍加改动 https://google.github.io/styleguide/csharp-style.html 书写规范 基础写法 Pascal和驼峰混用,参数用驼 ...
- C++代码书写规范——给新手程序员的一些建议
代码就是程序员的面子,无论是在工作中在电脑上写程序代码还是在面试时在纸上写演示代码我们都希望写出整洁,优雅的代码.特别在工作中当我们碰到需要维护别人的代码,或者是多人参与一个项目大家一起写代码的时候, ...
- 【转】JavaScript常用代码书写规范
javascript 代码规范 代码规范我们应该遵循古老的原则:“能做并不意味着应该做”. 全局命名空间污染 总是将代码包裹在一个立即的函数表达式里面,形成一个独立的模块. 不推荐 1 2 3 var ...
- JavaScript常用代码书写规范
javascript 代码规范 代码规范我们应该遵循古老的原则:“能做并不意味着应该做”. 全局命名空间污染 总是将代码包裹在一个立即的函数表达式里面,形成一个独立的模块. 不推荐 , y = ; c ...
- Python代码书写规范
Python 编码规范 一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不要使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在 ...
- c: c代码书写规范
排版: 较长的语句或函数过程参数(>80字符)要分成多行书写, 长表达式要在低优先级操作符处划分新行,操作符放在新行之首, 划分出的新行要进行适当的缩进,使排版整齐,语句可读 参考: 1. 运算 ...
随机推荐
- Loading class `com.mysql.jdbc.Driver'. This is deprecated
注意mysql的版本,pom.xml里面的版本.External Librarlies里面的mysql版本.application.properties版本都要检查 有时候还会报 Invalid bo ...
- Servlet获取配置信息(ServletConfig)
ServletConfig ServletConfig:当Servlet容器初始化Servlet时,Servlet容器会给Servlet的init方法传入一个ServletConfig.Servlet ...
- Hibernate第三天-Hibernate主配置信息
今天是学习Hibernate的第三天,主要分析一下Hibernate的配置文件中的信息 Hibernate中的配置文件有两种,第一种是主配置文件hibernate.cfg.xml,第二种是映射配置文件 ...
- vscode生成文件头注释(python)
文件→首选项→用户代码片段→选python 在大括号内添加如下内容: "Print infomation": { "prefix": "prelog& ...
- 清除定时器 和 vue 中遇到的定时器setTimeout & setInterval问题
2019-03更新 找到了更简单的方法,以setinterval为例,各位自行参考 mounted() { const that = this const timer = setInterval(fu ...
- 刷题10. Regular Expression Matching
一.题目说明 这个题目是10. Regular Expression Matching,乍一看不是很难. 但我实现提交后,总是报错.不得已查看了答案. 二.我的做法 我的实现,最大的问题在于对.*的处 ...
- 深入delphi编程理解之消息(四)使用TWMSysCommand结构体的WM_SysCommand消息应用
通过以下实例拦截窗体WM_SysCommand消息,我们可以获取到很多有趣的数据. 一.程序界面 二.程序代码 unit Unit1; interface uses Windows, Messages ...
- Go 语言 fmt.Sprintf (格式化输出)
Printf().Sprintf().Fprintf() 函数的区别用法是什么? 都是输出格式化字符串,只是输出到的目标不一样: Printf() 是把格式化字符串输出到标准到标准输出(一般是屏幕,可 ...
- 201771010135 杨蓉庆/张燕/杨玲《面对对象程序设计(java)》第十四周学习总结
1.实验目的与要求 (1) 掌握GUI布局管理器用法: (2) 掌握各类Java Swing组件用途及常用API 一.理论知识 Swing和MVC设计模式 (1)设计模式(Design patte ...
- Etcd Learning Notes
官网:https://etcd.io 官方项目地址:https://github.com/etcd-io/etcd 参考资料: https://www.hi-linux.com/posts/40915 ...