优点:
1.文件结构划分清晰
2.代码注释详细
缺点:
1.ViewController
应该有一个公共父类
不太合理:
@interface OMAdvertisementVC : UIViewController
@end
建议:
@interface OMAdvertisementVC : BaseViewController
@end
理由:
比如当 登录tokenId失效的时候,在每个界面都有可能失效,写在基类里就方便调用了
可以设置一些公共的东西,修改起来也比较方便
2.一些地方尽量不要简写
不太合理
@interface OMNavigation : UINavigationController
@end
建议:
@interface OMNavigationController : UINavigationController
@end
理由:
OC讲究见名知意
3.图片放置不规范,应该放到指定定位置
4.有些常用的控件尽量封装出去,而不要在用到的地方写一个方法出来
不太合理:
-(void)addAlertAction: (NSString *)msg
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
message:msg
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确定"
style:UIAlertActionStyleCancel
handler:nil];
//添加按钮
[alert addAction:cancel];
//显示
[self presentViewController:alert animated:YES completion:nil];
}
建议:
专门写一个工具类
放些常用的东西 self
是一个控制器 可以通过 UIApplication
拿到当前控制器实现解耦
理由: 代码简洁,便于维护
不太合理
建议:
理由:
6.避免直接在代码里引用第三方框架
不太合理
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
建议:
可以封装一个tableview
集成自UITableView
把刷新控件,无数据时的展位图封装进去。
理由:
方便进行统一修改,可能刷新控件需要高度自定义。可能在无数据和无网络的时候显示一些站位控件。实现解耦合。当有更合适的刷新框架需要更换时,更换会变得很轻松。像EGO被淘汰的一个。
7.控件尽量有一个基类
不太合理:
UIButton *creditAssignmentBtn = [[UIButton alloc]
initWithFrame:CGRectMake(productListBtn.width, productListBtn.y, SCREEN_WIDTH / 2, 45)];
[creditAssignmentBtn setTitle:@"我的P2P" forState:UIControlStateNormal];
[creditAssignmentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
creditAssignmentBtn.layer.borderColor = RGBColor(200, 200, 200).CGColor;
creditAssignmentBtn.layer.borderWidth = 0.5;
[creditAssignmentBtn setBackgroundColor:[UIColor whiteColor]];
[creditAssignmentBtn setBackgroundImage:
建议:
使用自己的 button 继承自 UIButton,或者用类目添加
理由:
不会过多的写重复代码,便于维护
8.封装控件的属性没必要暴漏出来
不太合理:
@class OMFinanceProductModel;
@interface OMFinanceProductCell : UITableViewCell
/**产品名*/
@property (nonatomic,weak) UILabel *titleLabel;
/**百分比*/
@property (nonatomic,weak) UILabel *percentLabel;
/**产品参加人数进度条*/
@property (nonatomic,weak) UIProgressView *progressView;
/**产品参加人数百分比*/
@property (nonatomic,weak) UILabel *progressPercentLabel;
/**产品持有时间*/
@property (nonatomic,weak) UILabel *timeLabel;
/**起投金额*/
@property (nonatomic,weak) UILabel *amountLabel;
/**cell背景*/
@property (nonatomic,weak) UIView *contextBackgroundView;
/**cell内容*/
@property (nonatomic,weak) UIView *contextView;
/**产品数据模型*/
@property (nonatomic,strong) OMFinanceProductModel *financeProductCellModel;
建议:
这些成为私有属性完全可以,理解什么是封装
理由:
保持.h
文件清洁,留下最有用的东西即可。
9.注册界面和找回密码界面有很多公共的东西可以在基类的基础上在抽取一个基类
不太合理
建议:
理由:
10.注册界面和找回密码界面有很多公共的东西可以在基类的基础上在抽取一个基类
不太合理
建议:
理由:
网友评论