澎湃iPad上线版本

letterInfoController.m 8.2KB

    // // letterInfoController.m // ThePaperHD // // Created by liyuan on 15/7/16. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "letterInfoController.h" #import "AsyncImageView.h" #import "MLNavigationController.h" #import "messageViewModel.h" #import "letterInfoTopicCell.h" #import "letterInfoImageCell.h" #import "letterInfoContentCell.h" @interface letterInfoController ()<messageViewModelDelegate>{ NSMutableArray *heightArray; } @property(nonatomic, strong)UIButton *closeBtn; @property(nonatomic, strong)UILabel *titleLabel; @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)messageViewModel *model; @property(nonatomic, strong)NSMutableArray *dataList; @end @implementation letterInfoController @synthesize letterId = _letterId; @synthesize dataList = _dataList; static NSString *infoTopicCellID = @"letterInfoTopicCell"; static NSString *infoImageCellID = @"letterInfoImageCell"; static NSString *infoContentCellID = @"letterInfoContentCell"; - (void)viewDidLoad { [super viewDidLoad]; [MobClick event:@"55"];//【需求】统计-iPad self.view.backgroundColor = [UIColor clearColor]; self.navigationController.navigationBar.hidden = YES; self.backView.frame = CGRectMake(hotAskListPopUpSize.width/2 - messagePopSize.width/2, 80, messagePopSize.width, messagePopSize.height-80); [self.view addSubview:self.closeBtn]; [self.view addSubview:self.titleLabel]; self.closeBtn.frame = CGRectMake(hotAskListPopUpSize.width/2 - messagePopSize.width/2, 0, 50, 80); [self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; self.titleLabel.frame = CGRectMake(0, 0, hotAskListPopUpSize.width, 80); [self.view addSubview:self.backView]; self.tableView.frame =self.backView.bounds; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.clipsToBounds = YES; [self configCanRefresh:NO canLoad:NO]; [self.backView addSubview:self.tableView]; self.model = messageViewModel.new; self.model.delegate = self; self.model.letterDic = @{@"letterId":_letterId}; [self.tableView registerClass:[letterInfoTopicCell class] forCellReuseIdentifier:infoTopicCellID]; [self.tableView registerClass:[letterInfoImageCell class] forCellReuseIdentifier:infoImageCellID]; [self.tableView registerClass:[letterInfoContentCell class] forCellReuseIdentifier:infoContentCellID]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark -- view - (UIButton*)closeBtn { if (!_closeBtn) { _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeBtn setImage:Image(@"login/popUpBack.png") forState:UIControlStateNormal]; [_closeBtn setImage:Image(@"login/popUpBack_h.png") forState:UIControlStateHighlighted]; [_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _closeBtn; } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.text = @"详情"; _titleLabel.textColor = [UIColor whiteColor]; _titleLabel.font = appFont(30, NO); } return _titleLabel; } - (UIView*)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame),messagePopSize.width, messagePopSize.height-80)]; _backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _backView; } #pragma mark -- set Data -(void)setLetterId:(NSString *)leId{ _letterId = leId; } -(void)setDataList:(NSMutableArray *)list{ _dataList = list; heightArray = [NSMutableArray array]; [_dataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([obj isKindOfClass:[letterBO class]]) { letterBO *letterBo = obj; CGFloat titleHeight = heightForString(letterBo.title, appFont(17, NO), CGRectGetWidth(self.tableView.bounds)-30, NSLineBreakByWordWrapping); [heightArray addObject:@(titleHeight + 61)]; }else if ([obj isKindOfClass:[imageObjectBO class]]){ imageObjectBO *imageBO = obj; if (isBlankString(imageBO.url)) { [heightArray addObject:@(0)]; }else{ CGFloat imageWidth; if ([imageBO.width floatValue] >= messagePopSize.width -30) { imageWidth = messagePopSize.width-30; }else{ imageWidth = [imageBO.width floatValue]; } CGFloat imageHeight = [imageBO.height floatValue]; CGFloat scale = imageHeight/imageWidth; [heightArray addObject:@(450*scale + 45)]; } }else if ([obj isKindOfClass:[NSString class]]){ NSString *contentStr = obj; CGFloat contentHeight = heightForAttributeString(getLineSpaceAttributedString(contentStr, 5, appFont(14, NO)), CGRectGetWidth(self.tableView.bounds)-30, appFont(14, NO)); [heightArray addObject:@(contentHeight+20)]; } }]; [self.tableView reloadData]; } #pragma mark -- tableView - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataList.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [heightArray[indexPath.row] floatValue]; } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([_dataList[indexPath.row] isKindOfClass:[letterBO class]]) { return [self getInfoTopicCell:tableView cellForRowAtIndexPath:indexPath]; }else if ([_dataList[indexPath.row] isKindOfClass:[imageObjectBO class]]){ return [self getInfoImageCell:tableView cellForRowAtIndexPath:indexPath]; }else{ return [self getInfoContentCell:tableView cellForRowAtIndexPath:indexPath]; } } - (UITableViewCell*)getInfoTopicCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { letterInfoTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:infoTopicCellID]; if (nil == cell) { cell = [[letterInfoTopicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:infoTopicCellID]; } cell.letterBo = _dataList[indexPath.row]; return cell; } - (UITableViewCell*)getInfoImageCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { letterInfoImageCell *cell = [tableView dequeueReusableCellWithIdentifier:infoImageCellID]; if (nil == cell) { cell = [[letterInfoImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:infoImageCellID]; } cell.imageBo = _dataList[indexPath.row]; return cell; } - (UITableViewCell*)getInfoContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { letterInfoContentCell *cell = [tableView dequeueReusableCellWithIdentifier:infoContentCellID]; if (nil == cell) { cell = [[letterInfoContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:infoContentCellID]; } cell.contentStr = _dataList[indexPath.row]; return cell; } #pragma mark - btn event - (void)closeEvent:(UIButton*)btn { [(MLNavigationController*)self.navigationController popViewControllerWithFlip]; } #pragma mark -- viewModel return data -(void)returnletterInfo:(letterBO *)data{ imageObjectBO *imageBo = setJsonDicToDataModel(data.image, [imageObjectBO class]); if (imageBo.url && !isBlankString(imageBo.url)) { NSMutableArray *array = [NSMutableArray arrayWithObjects:data,imageBo,data.detail, nil]; self.dataList = array; }else { NSMutableArray *array = [NSMutableArray arrayWithObjects:data,data.detail, nil]; self.dataList = array; } } @end