目录
1页面标题 安卓统一actionbar
2加载更多的处理方式
3日志
4数据库
5权限调用
6汉字存放地
7菜单存放地
8公用方法整理到一个类
9公用静态参数整理到一个类
10页面编写模板
1.页面标题
字体大小
static CGFloat Text_Size_Big = 16; //栗子:navigation标题
static CGFloat Text_Size_Main = 15;
static CGFloat Text_Size_Minor = 14;
static CGFloat Text_Size_Minor_Minor = 13;
static CGFloat Text_Size_Minor_Minor_Minor = 12;//像 列表的footer 文字。
标题名字
#pragma mark - 拜访总结
static NSString *const visitSummary = @"拜访总结";
static NSString *const submitSummarySuccess = @"提交成功";
static NSString *const submitSummaryFail = @"提交失败";
static NSString *const canNotBeyondLimit = @"不能超过255个字符";
使用 #pragma mark - 例子
而不使用 // 主要是为了方便查找,如下图:
2.加载更多的处理方式
使用 MJRefresh 框架
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
//上拉加载时需要执行的代码
}];
//有更多数据时调用
[self.tableView.mj_footer endRefreshing];
self.tableView.mj_footer.hidden = NO;//不隐藏footer
//没有更多数据时调用
[self.tableView.mj_footer endRefreshingWithNoMoreData];
self.tableView.mj_footer.hidden = YES;//隐藏footer
3.日志
// 3.自定义Log
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d \t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...);
#endif
使用方法 :直接调用 NSLog ,和原生使用方法相同
//我是栗子(例子)
NSLog(@"");
3.数据库
创建表
static FMDatabaseQueue *_queue;
// 0.获得沙盒中的数据库文件名
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"sysdb.sqlite"];
// 1.创建队列
_queue = [FMDatabaseQueue databaseQueueWithPath:path];
// 2.创表
[_queue inDatabase:^(FMDatabase *db) {
//默认菜单
[db executeUpdate:@"CREATE TABLE IF NOT EXISTS [t_menu] ([_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,[name] nvarchar(50) default '',[menuid] nvarchar(50) default '',[picurl] nvarchar(50) default '');"];
}];
[_queue close];
插入数据
NSMutableArray *sqlArray = @[
@{@"name":@"拜访总结",@"menuid":@"123",@"picUrl":@"www.xxx.com/a/b/c.png",},
@{@"name":@"拜访总结",@"menuid":@"123",@"picUrl":@"www.xxx.com/a/b/c.png"}].mutableCopy;
[WLBSysDBTool execSql:@"delete from t_menu"]; //执行一条sql语句,删除表中数据
if (sqlArray.count != 0) {
NSString *sqlInsert=@"insert into [t_menu](name,menuid,picurl) select "; //向表 t_menu 插入数据的 sql
for (NSDictionary *dic in sqlArray) {
NSString *name = [dic objectForKey:@"name"] ? [dic objectForKey:@"name"] : @"";
NSString *menuid = [dic objectForKey:@"menuid"] ? [dic objectForKey:@"menuid"] : @"";
NSString *picUrl = [dic objectForKey:@"picUrl"] ? [dic objectForKey:@"picUrl"] : @"";
sqlInsert = [NSString stringWithFormat:@"%@'%@','%@','%@' ",sqlInsert,name,menuid,picUrl];
if (dic == [sqlArray lastObject]) {
sqlInsert = [NSString stringWithFormat:@"%@;",sqlInsert];
} else {
sqlInsert = [NSString stringWithFormat:@"%@union all select ",sqlInsert];
}
}
[WLBSysDBTool execSql:sqlInsert];//向表中插入数据
//获得数据
NSMutableArray *sqlArray = [WLBSysDBTool getArrayFromSql:@"select menuid,name,picurl from t_menu"];
for (NSDictionary *dic in sqlArray) {
MoreApplyModel *model = [MoreApplyModel new];//自己的model
model.name = [dic objectForKey:@"name"];//对应select name
model.picurl = [dic objectForKey:@"picurl"];
model.menuid = [dic objectForKey:@"menuid"];
[self.dataSource addObject:model];
}
5.权限调用
安卓:
//细节权限
RecheckMenuJur.getDetailJur(A);
参数A:手机端明细权限id
//erp权限
RecheckMenuJur.getERPJur(A);
参数A:erp权限id
(最后返回的类型是boolean,如果不需要判断,你也传了,那也是返回false)ios:
//erp权限
[RecheckMenuJur getERPJur:@"A"]
//细节权限
[RecheckMenuJur getDetailJur:@"A"]
参数都和上面一样
6.汉字存放地
7.菜单存放地
- (void)addToData {
//第一种添加方式
[self setVCName:@"VisitStoreController" menuId:CAR_DISTRIBUTION_STORE_SALES pageparam:@""];
//第二种添加方式
[self setMenuId:CAR_DISTRIBUTION_STORE_SALES getTouch:^(UIViewController *fromVC){
[MenuTool fromUIViewController:fromVC toVCName:@"VisitStoreController" pageparam:@""];
}];
}
8公用方法整理到一个类
9公用静态参数整理到一个类
10页面编写模板
ViewController.h
#import
@interface ViewController : UIViewController
+ (void)fromVC:(UIViewController *)fromVC callback:(void(^)(void))callback;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property (copy, nonatomic) void (^callback)(void);
@property (strong ,nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *dataSource;
@property (strong, nonatomic) UIButton *button;
@end
@implementation ViewController
#pragma mark - instancetype
+ (void)fromVC:(UIViewController *)fromVC callback:(void(^)(void))callback {
ViewController *vc = [[ViewController alloc] init];
vc.title = @"模板";
vc.callback = callback;
[fromVC.navigationController pushViewController:vc animated:YES];
// [fromVC presentViewController:vc animated:YES completion:nil];
}
#pragma mark - setter
- (void)setCallback:(void (^)(void))callback {
_callback = callback;
}
#pragma mark - getter
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] init];
}
return _tableView;
}
- (NSMutableArray *)dataSource {
if (!_dataSource) {
_dataSource = [NSMutableArray new];
}
return _dataSource;
}
- (UIButton *)button {
if (!_button) {
_button = [UIButton buttonWithType:UIButtonTypeSystem];
[_button addTarget:self action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside];
}
return _button;
}
#pragma mark - lifeCycle
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initViews];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
#pragma mark - private methods
- (void)initData {
//初始化数据
}
- (void)loadData {
//网络请求数据
}
#pragma mark - views
- (void)initViews {
[self.view addSubview:self.button];
[self.view addSubview:self.tableView];
[self.button mas_makeConstraints:^(MASConstraintMaker *make) {
}];
}
#pragma mark - delegate
#pragma makr - UITableViewDelegate, UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return [UITableViewCell new];
}
#pragma mark - action /callback
- (void)doButton:(UIButton *)sender {
if (self.callback) {
self.callback();
}
}
@end