zoukankan      html  css  js  c++  java
  • 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 = 10;  //定义静态变量
    
    #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(100, 100, 100, 40);
        [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 6;//_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(0, 0, 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

      附件:示例代码。

  • 相关阅读:
    powerdesigner与数据库之间的连接
    D9-Android自定义控件之动画篇1-ObjectAnimator
    01-React搭建react环境及SCSS的配置
    开源计划之--Android绘图库--LogicCanvas
    5-VVI-材料设计之ToolBar
    4-VVI-材料设计之沉浸标题栏和TextInputLayout
    D8-Android自定义控件之DotNum及item复用问题
    O3-开源框架使用之Butterknife 8.8.1及源码浅析
    TIII-Android技术篇之反射
    TVI-Android技术篇之注解Annotation
  • 原文地址:https://www.cnblogs.com/ZachRobin/p/7280994.html
Copyright © 2011-2022 走看看