//
|
// OnlySpecialController.m
|
// BuWanVideo2.0
|
//
|
// Created by weikou2016 on 16/8/19.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "OnlySpecialController.h"
|
#import "OnlySpecialOne.h"
|
#import "OnlySpecialTwo.h"
|
#import "OnlySpecialThere.h"
|
#import "XYRDetailViewController.h"
|
|
@interface OnlySpecialController ()<UITableViewDataSource,UITableViewDelegate>{
|
NSMutableArray * dataarr; //下面的视频数据源
|
NSMutableDictionary *titledic; //标题数据
|
float textheight;
|
NSMutableString *str;
|
int page;
|
UITableView *tableview;
|
}
|
|
@end
|
|
@implementation OnlySpecialController
|
|
@synthesize Id;
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
//[MobClick beginLogPageView:@"进入单个专题"];
|
[self initScene];
|
}
|
|
-(void)dealloc{
|
//[MobClick beginLogPageView:@"退出单个专题"];
|
}
|
|
-(void)initScene{
|
self.navigationItem.title = @"专题合集";
|
|
self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]};;
|
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
|
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
[button setImage:[[UIImage imageNamed:@"详情页面返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
|
[button addTarget:self action:@selector(back:)
|
forControlEvents:UIControlEventTouchUpInside];
|
button.frame = CGRectMake(0, 0, 32, 32);
|
UIBarButtonItem *iconBarItem=[[UIBarButtonItem alloc] initWithCustomView:button];
|
self.navigationItem.leftBarButtonItem = iconBarItem;
|
|
self.view.backgroundColor = kGlobalBackgroundColor;
|
|
tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
|
tableview.dataSource = self;
|
tableview.delegate = self;
|
[self.view addSubview:tableview];
|
tableview.backgroundColor = kGlobalBackgroundColor;
|
[tableview registerNib:[UINib nibWithNibName:@"OnlySpecialOne" bundle:nil] forCellReuseIdentifier:@"OnlySpecialOne"];
|
[tableview registerNib:[UINib nibWithNibName:@"OnlySpecialTwo" bundle:nil] forCellReuseIdentifier:@"OnlySpecialTwo"];
|
[tableview registerNib:[UINib nibWithNibName:@"OnlySpecialThere" bundle:nil] forCellReuseIdentifier:@"OnlySpecialThere"];
|
tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
|
tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(updatahead)];
|
dataarr = [NSMutableArray new];
|
titledic = [NSMutableDictionary new];
|
//加载数据
|
[tableview.mj_header beginRefreshing];
|
}
|
|
-(void)updatahead{
|
page = 1;
|
[[YTHNetInterface startInterface]getFoundOnlySpecial:[YTHsharedManger startManger].Uid withPage:[NSString stringWithFormat:@"%d",page] WithId:[NSString stringWithFormat:@"%d",Id] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error){
|
if(isSuccessful){
|
dataarr = [[result objectForKey:@"Data"]objectForKey:@"data"];
|
titledic = [[result objectForKey:@"Data"]objectForKey:@"special"];
|
if(dataarr.count > 0 && titledic.count > 0){
|
textheight = [self autoHeightWithStr:[titledic objectForKey:@"Introduction"] WithFont:12 WithWidth:KScreenW -20].floatValue;
|
[tableview reloadData];
|
page++;
|
}
|
}else{
|
NSLog(@"%@",error);
|
if ([error compare:@"似乎已断开与互联网的连接。"] == 0) {
|
[self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"];
|
}
|
}
|
[tableview.mj_header endRefreshing];
|
}];
|
}
|
|
-(void)updatafoot{
|
[[YTHNetInterface startInterface]getFoundOnlySpecial:[YTHsharedManger startManger].Uid withPage:[NSString stringWithFormat:@"%d",page] WithId:[NSString stringWithFormat:@"%d",Id] WithSystem:@"1" WithBlock:^(BOOL isSuccessful, id result, NSString *error){
|
if(isSuccessful){
|
|
NSArray * newdata = [[result objectForKey:@"Data"]objectForKey:@"data"];
|
if(newdata.count > 0){
|
[dataarr addObjectsFromArray:newdata];
|
[tableview reloadData];
|
page++;
|
}
|
}else{
|
NSLog(@"%@",error);
|
}
|
[tableview.mj_footer endRefreshing];
|
}];
|
}
|
|
#pragma mark UITableViewDataSource UITableViewDelegate
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
if(section == 0){
|
return 1;
|
}else if(section == 1){
|
return 1;
|
}else{
|
return dataarr.count;
|
}
|
}
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
return 3;
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
if(indexPath.section == 0){ //Introduction
|
OnlySpecialOne * cell = [tableView dequeueReusableCellWithIdentifier:@"OnlySpecialOne" forIndexPath:indexPath];
|
[cell.image setYthImageWithURL:[titledic objectForKey:@"Picture"] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
return cell;
|
}else if(indexPath.section == 1){
|
OnlySpecialTwo * cell = [tableView dequeueReusableCellWithIdentifier:@"OnlySpecialTwo" forIndexPath:indexPath];
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
if(!cell.autoheight && titledic.count > 0){
|
cell.lableheight.constant += textheight;
|
cell.autoheight = YES;
|
}
|
|
cell.title.text = [titledic objectForKey:@"Name"];
|
cell.lable.text = [titledic objectForKey:@"Introduction"];
|
return cell;
|
|
}else{
|
|
OnlySpecialThere * cell = [tableView dequeueReusableCellWithIdentifier:@"OnlySpecialThere" forIndexPath:indexPath];
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
NSDictionary *dic = dataarr[indexPath.row];
|
NSLog(@"%@",dic);
|
cell.backgroundColor = kGlobalBackgroundColor;
|
[cell.image setYthImageWithURL:[dic objectForKey:@"Hpicture"] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
|
// CGFloat score = [[dic objectForKey:@"Score"]doubleValue];
|
// if (score != 0) {
|
// cell.grade.text = [NSString stringWithFormat:@"评分:%.1f",score];
|
// }
|
cell.grade.text = [dic objectForKey:@"Tag"];
|
cell.title.text = [dic objectForKey:@"Name"];
|
cell.playnum.text = [dic objectForKey:@"WatchCount"];
|
NSNumber *number = [dic objectForKey:@"CommentCount"];
|
cell.commentnum.text = [NSString stringWithFormat:@"%d",number.intValue];
|
|
return cell;
|
}
|
return nil;
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
if(indexPath.section == 0){
|
return KScreenW/16*7;
|
}else if(indexPath.section == 1){
|
if(titledic.count > 0){
|
return 80 + textheight;//计算增加的速度
|
}
|
return 0;
|
}else{
|
return 95;
|
}
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
if(indexPath.section ==2){
|
NSDictionary * dic = dataarr[indexPath.row];
|
XYRDetailViewController *play=[[XYRDetailViewController alloc]init];
|
[YTHsharedManger startManger].preController = self;
|
play.modalPresentationStyle = 0;
|
play.Model = [XYRVideoInfoModel yy_modelWithDictionary:dic];
|
[self presentViewController:play animated:YES completion:^{
|
}];
|
}
|
}
|
|
/**
|
* 计算字的高度
|
*/
|
-(NSString*)autoHeightWithStr:(NSString*)strs WithFont:(int)font_i WithWidth:(float)width{
|
UILabel *lb = [UILabel new];
|
lb.text = strs;
|
lb.font = [UIFont systemFontOfSize:font_i];
|
lb.numberOfLines = 0;
|
CGSize size = [lb sizeThatFits:CGSizeMake(width, MAXFLOAT)];
|
return [NSString stringWithFormat:@"%f",size.height]; //减去当前字号的大小 由于XIB写了一排
|
}
|
|
-(void)back:(UIButton*)sender{
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
|
|
@end
|