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

      附件:示例代码。

  • 相关阅读:
    css flex布局应用
    Java 中 List、HashTable、HashMap、TreeMap
    Java 面向对象的三大特征
    Java-冒泡排序算法
    单例模式- 实现方式
    Mac
    Appium DesiredCapabilities 参数设置
    Mac- appium 环境配置
    PHP安装+使用
    mac 安装protobuf,并编译
  • 原文地址:https://www.cnblogs.com/ZachRobin/p/7280994.html
Copyright © 2011-2022 走看看