BaseViewController.m
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// BaseViewController.m
// ZXBaseProject
//
// Created by 张旭 on 2017/1/10.
// Copyright © 2017年 cnlive. All rights reserved.
//
#import "BaseViewController.h"
@interface BaseViewController ()
@end
@implementation BaseViewController
- (id)init {
self = [super init];
if (self) {
[self initParameters];
self.isModalButton = NO;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
[self navigationSet];
[self bindModel];
[self bindView];
[self bindAction];
}
- (void)initParameters {}
/**
* 导航按钮设置
*/
- (void)navigationSet{
self.btnRight = [UIButton buttonWithType:UIButtonTypeCustom];
[_btnRight setFrame:CGRectMake(0, 0, 25, 20)];
[_btnRight addTarget:self action:@selector(onRightAction) forControlEvents:UIControlEventTouchUpInside];
_btnRight.titleLabel.textAlignment = NSTextAlignmentRight;
_btnRight.titleLabel.font = [UIFont systemFontOfSize:15];
UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithCustomView:_btnRight];
self.navigationItem.rightBarButtonItem = rightBtn;
self.btnRight.hidden = YES;
self.btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[_btnLeft setFrame:CGRectMake(0, 0, 30, 30)];
[_btnLeft addTarget:self action:@selector(onBackAction) forControlEvents:UIControlEventTouchUpInside];
[_btnLeft setBackgroundImage:[UIImage imageNamed:@"fanhui_default"] forState:UIControlStateNormal];
[_btnLeft setBackgroundImage:[UIImage imageNamed:@"fanhui_focused"] forState:UIControlStateHighlighted];
_btnLeft.highlighted = NO;
UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithCustomView:_btnLeft];
UIBarButtonItem * negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -8;//默认leftItemX == 18,要求距左边10
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:negativeSpacer,backItem, nil]];
if ((self.navigationController.viewControllers[0] == self) && (self.isModalButton == NO)) {
_btnLeft.hidden = YES;
}
}
/**
* 加载视图
*/
- (void)bindView {
}
/**
* 加载模型
*/
- (void)bindModel {
}
/**
* 加载方法
*/
- (void)bindAction {
}
- (void)loadViews {
}
//*****************************************************************
// MARK: - actions
//*****************************************************************
/**
* 导航控制器上角按钮方法
*/
- (void)onBackAction {
if(self.isModalButton) {
[self dismissViewControllerAnimated:YES completion:NULL];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
}
- (void)onRightAction
{
}
/** 词典转换为字符串 */
- (NSString*)dictionaryToJson:(NSDictionary *)dic {
NSError *parseError = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
- (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