您的位置:首页 > 产品设计 > UI/UE

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息