前段时间一直在做后台开发,所以好长时间没搞过iOS了 ,不过最近又开启了iPad开发,,(毕竟是外包,公司要求做什么 那就做什么咯)
我一直都比较习惯在controller中写的代码很少,视图层全部都单独写出一个类,前段时间刚写了这个页面的封装,(当你看到这个页面不要惊慌,因为我这期的项目的页面全部都是这种的。。。)
先说一下headerview的封装吧,,由于本人不擅长文字交流 ,那就直接代码好了。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView.tag == 100) {
TaskOneTableViewCell *oneCell = [tableView dequeueReusableCellWithIdentifier:@"oneCell"];
if (!oneCell) {
oneCell = [[TaskOneTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"oneCell"];
}
oneCell.selectionStyle = UITableViewCellSelectionStyleNone;
oneCell.Model = [[ModelStore shareInstance]getbiddersMentsData][indexPath.row];
return oneCell;
}else{
qianchengTableViewCell *qiancell = [tableView dequeueReusableCellWithIdentifier:@"qianCell"];
if (!qiancell) {
qiancell = [[qianchengTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"qianCell"];
}
qiancell.actModel = [[ModelStore shareInstance]getactivitiesArrData][indexPath.row];
return qiancell;
}
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if (tableView.tag == 100 || tableView == self.TableView) {
self.one = [[taskOne alloc]init];
self.one.backgroundColor = COLOR_DOCK_COLOR;
self.one.taskModel = [[ModelStore shareInstance]getTaskTakenData][section];
return self.one;
}else if (tableView.tag == 102 || tableView == self.QianchengTableView){
self.twoheader = [[taskTwoHeader alloc]init];
return self.twoheader;
}
return nil;
}
这个是在Controller里面写的代码,然后现在去封装的headerView看下代码
@class taskFoot;
@protocol taskFootDelegate
- (void)taskFootAcc:(taskFoot*)acc url:(NSString *)str;//查看附件
@end
typedef void(^ClickTaskOneControllerBlock)(NSString * contentMsg);
@interface taskFoot : UIView
@property(nonatomic,weak) iddelegate;
@property (nonatomic,copy) ClickTaskOneControllerBlock ClickTaskOneControllerBlock;
@property (nonatomic,strong)taskModel *taskModel;
@property (nonatomic,strong)Attachments *attModel;
- (void)updateData:(taskModel *)taskModel and:(Attachments *)nextmodel;
@property(nonatomic,strong)UILabel *PRsave;//PR节约率
@property(nonatomic,strong)UILabel *ProSave;//采购业绩率
再看.m中的
//实现view中代理传参数
- (void)accClick:(UIButton *)butt{
if ([self.delegate respondsToSelector:@selector(taskFootAcc:url:)]) {
[self.delegate taskFootAcc:self url:self.accURL];
}
}
#pragma mark-textField代理
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[textField keyBoardDiss];
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}