developer
2023-05-20 c1ffd99c4b60066774eb2c97b31e4aaa014e7f51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//
//  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