UITableView 抽取及控制器的调用整合
2016-05-19 00:00
316 查看
摘要: UITableView 抽取及控制器的调用整合
#import "FatherView.h"
@interface AdminSafetyView : FatherView
@property (nonatomic, copy) void (^clickedAdminSafetyViewCell)(NSInteger index);
@end
================================================================================
#import "AdminSafetyView.h"
@interface AdminSafetyView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) UIView * topView;
@end
@implementation AdminSafetyView
- (instancetype)init{
self = [super init];
if (self) {
[self initTopView];
[self initTableView];
}
return self;
}
- (void)initTopView{
_topView = [[UIView alloc] init];
_topView.backgroundColor = BACKGROUND_COLOR;
[self addSubview:_topView];
[_topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).offset(1);
make.left.and.right.equalTo(self);
make.height.equalTo(@19);
}];
}
- (void)initTableView{
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.backgroundColor = BACKGROUND_COLOR;
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.scrollEnabled = NO;
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 0);
_tableView.separatorColor = boroerAndLineColor;
[self addSubview:_tableView];
WS(ws);
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(ws.mas_top).offset(20);
make.left.and.right.bottom.equalTo(ws);
}];
}
#pragma mark - 协议
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
}
//自定义cell;
if (indexPath.row == 0) {
cell.textLabel.text = @"修改登录密码";
}
else {
cell.textLabel.text = @"找回密码";
}
cell.textLabel.textColor = RGBAUIColorFrom(0x323232, 1.0);
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 45.0f;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.clickedAdminSafetyViewCell(indexPath.row);
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001f;
}
@end
================================================================================================
#import "AdminSafetyViewController.h"
#import "AdminSafetyView.h"
#import "ChangePWDViewController.h"
#import "BackPWDViewController.h"
@interface AdminSafetyViewController ()
@property (nonatomic,strong) AdminSafetyView *adminSafetyView;
@end
@implementation AdminSafetyViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initView];
[self initClicked];
}
- (void)initView{
[self initLeftItemWithName:nil orImage:@"btn_return"];
[self.adminSafetyView setBackgroundColor:BACKGROUND_COLOR];
}
- (AdminSafetyView *)adminSafetyView{
WS(ws);
if (!_adminSafetyView) {
_adminSafetyView = [[AdminSafetyView alloc]init];
[self.view addSubview:_adminSafetyView];
[_adminSafetyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(ws.view).offset(65);
make.left.right.bottom.equalTo(ws.view);
}];
}
return _adminSafetyView;
}
- (void)initClicked{
WS(ws);
_adminSafetyView.clickedAdminSafetyViewCell = ^(NSInteger index)
{
switch (index) {
case 0:{
ChangePWDViewController * changeVC = [[ChangePWDViewController alloc] init];
[ws.navigationController pushViewController:changeVC animated:YES];
}
break;
case 1:{
BackPWDViewController * backVC = [[BackPWDViewController alloc] init];
[ws.navigationController pushViewController:backVC animated:YES];
}
break;
default:
break;
}
};
}
@end
#import "FatherView.h"
@interface AdminSafetyView : FatherView
@property (nonatomic, copy) void (^clickedAdminSafetyViewCell)(NSInteger index);
@end
================================================================================
#import "AdminSafetyView.h"
@interface AdminSafetyView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) UIView * topView;
@end
@implementation AdminSafetyView
- (instancetype)init{
self = [super init];
if (self) {
[self initTopView];
[self initTableView];
}
return self;
}
- (void)initTopView{
_topView = [[UIView alloc] init];
_topView.backgroundColor = BACKGROUND_COLOR;
[self addSubview:_topView];
[_topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).offset(1);
make.left.and.right.equalTo(self);
make.height.equalTo(@19);
}];
}
- (void)initTableView{
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableView.backgroundColor = BACKGROUND_COLOR;
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.scrollEnabled = NO;
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 0);
_tableView.separatorColor = boroerAndLineColor;
[self addSubview:_tableView];
WS(ws);
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(ws.mas_top).offset(20);
make.left.and.right.bottom.equalTo(ws);
}];
}
#pragma mark - 协议
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
}
//自定义cell;
if (indexPath.row == 0) {
cell.textLabel.text = @"修改登录密码";
}
else {
cell.textLabel.text = @"找回密码";
}
cell.textLabel.textColor = RGBAUIColorFrom(0x323232, 1.0);
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 45.0f;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.clickedAdminSafetyViewCell(indexPath.row);
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001f;
}
@end
================================================================================================
#import "AdminSafetyViewController.h"
#import "AdminSafetyView.h"
#import "ChangePWDViewController.h"
#import "BackPWDViewController.h"
@interface AdminSafetyViewController ()
@property (nonatomic,strong) AdminSafetyView *adminSafetyView;
@end
@implementation AdminSafetyViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initView];
[self initClicked];
}
- (void)initView{
[self initLeftItemWithName:nil orImage:@"btn_return"];
[self.adminSafetyView setBackgroundColor:BACKGROUND_COLOR];
}
- (AdminSafetyView *)adminSafetyView{
WS(ws);
if (!_adminSafetyView) {
_adminSafetyView = [[AdminSafetyView alloc]init];
[self.view addSubview:_adminSafetyView];
[_adminSafetyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(ws.view).offset(65);
make.left.right.bottom.equalTo(ws.view);
}];
}
return _adminSafetyView;
}
- (void)initClicked{
WS(ws);
_adminSafetyView.clickedAdminSafetyViewCell = ^(NSInteger index)
{
switch (index) {
case 0:{
ChangePWDViewController * changeVC = [[ChangePWDViewController alloc] init];
[ws.navigationController pushViewController:changeVC animated:YES];
}
break;
case 1:{
BackPWDViewController * backVC = [[BackPWDViewController alloc] init];
[ws.navigationController pushViewController:backVC animated:YES];
}
break;
default:
break;
}
};
}
@end
相关文章推荐
- Query采用each方法遍历
- Exception in thread "main" org.hibernate.QueryException: illegal attempt to dereference collection
- LeetCode 334. Increasing Triplet Subsequence
- codeforces D. Maximum Value
- 347. Top K Frequent Elements
- iOS开发系列--UITableView全面解析
- HDU - 1171 Number Sequence(Kmp)
- UVA 11324 - The Largest Clique(SCC缩点 + DP)
- Codeforces #353 div.2 Infinite Sequence&Restoring Painting&Money Transfers前三题题解
- Leetcode 128. Longest Consecutive Sequence
- UVA - 11235 —— Frequent values 【RMQ】
- POJ 1141 —— Brackets Sequence
- UVA - 11538 —— Chess Queen
- UI基础第二天(自学)
- iOS开发之高级视图—— UITableView常用方法
- Android酷炫实用的开源框架(UI框架)
- iOS组件之UILabel
- UIButton中UIImage的使用
- sdut 3252 Lowest Unique Price set
- 300. Longest Increasing Subsequence最长递增子序列