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

  附件:示例代码。

 

转载于:https://www.cnblogs.com/ZachRobin/p/7280994.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值