|
//
// topicBannersController.m
// ThePaperBase
//
// Created by liyuan on 15/10/28.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicBannersController.h"
#import "topicContentController.h"
#import "topicListCell.h"
#import "topicBannerLabelCell.h"
#import "topicBannerCollectCell.h"
@interface topicBannersController ()<topicBannerDelegate,UIGestureRecognizerDelegate>{
NSMutableArray *heightArray;
CGFloat statusHeight;
}
@property(nonatomic, strong)NSMutableArray *dataList;
@property(nonatomic, strong)UIButton *backBtn;
@end
@implementation topicBannersController
@synthesize contentBo = _contentBo;
@synthesize dataList = _dataList;
static NSString *labelCellID = @"topicBannerLabelCell";
static NSString *collectCellID = @"topicBannerCollectCell";
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBarHidden = YES;
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
// self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerClass:[topicBannerLabelCell class] forCellReuseIdentifier:labelCellID];
[self.tableView registerClass:[topicBannerCollectCell class] forCellReuseIdentifier:collectCellID];
[self.view addSubview:self.backBtn];
[self setContentFramWithOrirentation];
[self configCanRefresh:NO canLoad:YES];
UISwipeGestureRecognizer *rightGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightPopSwipeGestureHandler:)];
[rightGesture delaysTouchesBegan];
rightGesture .numberOfTouchesRequired = 1;
rightGesture.delegate = self;
rightGesture .direction = UISwipeGestureRecognizerDirectionRight;
// self.rightGesture.enabled = NO;
[self.view addGestureRecognizer:rightGesture ];
// [self.view addSubview:self.descLabel];
// Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
//【倒退】【适配性】问吧:【精选】中,点击顶部图片进入查看,竖屏时内容显示不全(bug:6121)
// if (isIOS7) {
// statusHeight = 18;
// }else {
// statusHeight = 18;
// }
// self.tableView.frame = CGRectMake(70,statusHeight , CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
}
-(UIButton *)backBtn{
if (!_backBtn) {
_backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_backBtn.frame = CGRectMake(0,CGRectGetHeight(self.view.bounds)-100, 70, 70);
[_backBtn setImage:Image(@"detailPage/contentBackImg.png") forState:UIControlStateNormal];
// [_backBtn setBackgroundImage:Image(@"detailPage/contentBackImg.png") forState:UIControlStateSelected];
[_backBtn setImage:Image(@"detailPage/contentBackImg_s.png") forState:UIControlStateHighlighted];
[_backBtn setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[_backBtn addTarget:self action:@selector(popBack:) forControlEvents:UIControlEventTouchUpInside];
}
return _backBtn;
}
#pragma mark -- btn handler
-(void) popBack:(UIButton *)btn{
[self.navigationController popViewControllerAnimated:YES];
}
- (void)rightPopSwipeGestureHandler:(id)sender {
if (!self.isPresent) {
[self.navigationController popViewControllerAnimated:YES];
}else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark -- setData
-(void)setContentBo:(listContObjectVO *)bo{
_contentBo = bo;
NSDictionary *dic = @{@"n":_contentBo.forwordNodeId};
[Remote doJsonAction:1
requestUrl:topicSpecURL
parameter:dic
delegate:self];
}
-(void)setDataList:(NSMutableArray *)list{
_dataList = list;
heightArray = [NSMutableArray array];
[_dataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[specialObjectBO class]]) {
// 125+60
specialObjectBO *specBo = obj;
CGFloat descHeight = returnTextHeightWithRTLabel(specBo.desc, 1300/2, appFont(18, NO), 12);
[heightArray addObject:@(descHeight+140)];
}else{
NSMutableArray *coList = obj;
float fnum = (float)coList.count/2;
double num = ceil(fnum);
[heightArray addObject:@(20 + (num-1)*12 +num*230)];
}
}];
[self.tableView reloadData];
}
#pragma mark -- oritation
#pragma mark - set and get method
- (void)statusBarOrientationChange:(NSNotification *)notification{
[self setContentFramWithOrirentation];
}
- (void)setContentFramWithOrirentation {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight
|| orientation ==UIInterfaceOrientationLandscapeLeft) {
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.tableView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
}else {
self.view.frame = CGRectMake(0, 0, 768, 1024);
self.tableView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
}
self.backBtn.frame = CGRectMake(10, CGRectGetHeight(self.view.bounds)-100, 70, 70);
}
#pragma mark - table view delegate and datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [heightArray[indexPath.row] floatValue];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
id obj = self.dataList[indexPath.row];
if ([obj isKindOfClass:[specialObjectBO class]]) {
return [self topCell:tableView cellForRowAtIndexPath:indexPath];
}else{
return [self collectCell:tableView cellForRowAtIndexPath:indexPath];
}
}
- (UITableViewCell*)topCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
topicBannerLabelCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:labelCellID];
if (nil == cell) {
cell = [[topicBannerLabelCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:labelCellID];
}
cell.specBO = self.dataList[indexPath.row];
return cell;
}
- (UITableViewCell*)collectCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
topicBannerCollectCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:collectCellID];
if (nil == cell) {
cell = [[topicBannerCollectCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:collectCellID];
}
cell.delegate = self;
cell.dataList = self.dataList[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - remote
-(void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData{
specialObjectBO *specialBO = setJsonDicToDataModel(responsData[@"specialInfo"], [specialObjectBO class]);
NSArray *list = responsData[@"topicList"];
NSMutableArray *temp = [NSMutableArray array];
[temp addObject:specialBO];
NSMutableArray *collectList = [NSMutableArray array];
[list enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
if (![dic[@"forwordType"] isEqualToString:@"4"]) {
TopicInfoBO *bo = setJsonDicToDataModel(dic, [TopicInfoBO class]);
bo.isFirstCard = @"0";
[collectList addObject:bo];
}
}];
[temp addObject:collectList];
self.dataList = temp;
self.nextUrl = @"";
}
#pragma mark -- collect delegate
-(void)gotoTopicInfo:(TopicInfoBO *)topic{
topicContentController *vc = [[topicContentController alloc]init];
vc.preTopicInfo = topic;
userBO *user = setJsonDicToDataModel(topic.userInfo, [userBO class]);
vc.creatUser = user;
[self.navigationController pushViewController:vc animated:YES];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
|