//
|
// 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
|