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
//
//  StarsController.m
//  BuWanVideo2.0
//
//  Created by weikou2016 on 16/8/18.
//  Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "StarsController.h"
#import "SubregionViewCollectionViewCell.h"
#import "IndividualStarController.h"
 
@interface StarsController ()<UICollectionViewDataSource,UICollectionViewDelegate>{
    UICollectionView * collection;
    NSMutableArray *data;
    int page;
}
 
@end
 
@implementation StarsController
 
- (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 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;
    
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
    flowlayout.scrollDirection = UICollectionViewScrollDirectionVertical;//滚动方向
    flowlayout.minimumLineSpacing = KScreenW/25;//行间距
    flowlayout.minimumInteritemSpacing=KScreenW/25;//item之间的距离
    flowlayout.itemSize = CGSizeMake((KScreenW)/5, (KScreenW)/5+30);//设置itme的大小
    flowlayout.sectionInset = UIEdgeInsetsMake(20,20,20,20);//设置itme之间的间距
    
    collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0 , KScreenW,KScreenH) collectionViewLayout:flowlayout];
    collection.dataSource = self;
    collection.delegate = self;
    collection.backgroundColor = [UIColor whiteColor];
    collection.scrollEnabled = YES;
    [self.view addSubview:collection];
    
    [collection registerNib:[UINib nibWithNibName:@"SubregionViewCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"SubregionViewCollectionViewCell"];
    
    data = [NSMutableArray new];
    collection.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(updatahead)];
    collection.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(updatafoot)];
    
    [collection.mj_header beginRefreshing];
}
 
-(void)back:(UIButton*)sender{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
 
-(void)updatahead{
    [SVProgressHUD showWithStatus:@"疯狂加载中"];
    page = 1;
    [[YTHNetInterface startInterface]getHotStarsWithUid:[YTHsharedManger startManger].Uid withSystem:@"1" withPage:[NSString stringWithFormat:@"%d",page] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            [SVProgressHUD dismiss];
            data =[[result objectForKey:@"Data"] objectForKey:@"data"];
            if(data.count > 0){
                page++;
                [collection reloadData];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:@"网络连接失败"];
            NSLog(@"%@",error);
        }
        [collection.mj_header endRefreshing];
    }];
}
 
-(void)updatafoot{
    [[YTHNetInterface startInterface]getHotStarsWithUid:[YTHsharedManger startManger].Uid withSystem:@"1" withPage:[NSString stringWithFormat:@"%d",page] withBlock:^(BOOL isSuccessful, id result, NSString *error) {
        if(isSuccessful){
            NSArray *tempdata =[[result objectForKey:@"Data"] objectForKey:@"data"];
            if(tempdata.count > 0){
                [data addObjectsFromArray:tempdata];
                [collection reloadData];
                page++;
            }
        }else{
            NSLog(@"%@",error);
        }
        [collection.mj_footer endRefreshing];
    }];
}
 
 
#pragma mark   UICollectionViewDataSource   UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return data.count;
}
 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    SubregionViewCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SubregionViewCollectionViewCell" forIndexPath:indexPath];
    NSDictionary *dic = data[indexPath.row];
    
    cell.imageH.constant=cell.frame.size.width;
    cell.image.layer.cornerRadius=cell.frame.size.width/2;
    cell.text.text = [dic objectForKey:@"Name"];
    [cell.image setContentMode:UIViewContentModeScaleAspectFill];
    [cell.image setYthImageWithURL:[dic objectForKey:@"Portrait"] placeholderImage:[UIImage imageNamed:@"关注默认头像"]];
 
    return cell;
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}
 
#pragma mark -UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
        IndividualStarController *individualstar = [IndividualStarController new];
        individualstar.data = [[NSMutableDictionary alloc]initWithDictionary:data[indexPath.row]];
        [self.navigationController pushViewController:individualstar animated:YES];
}
@end