IVTMyLiveViewController.m
5.61 KB
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
//
// IVTMyLiveViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/23.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTMyLiveViewController.h"
#import "IVTMyLiveCollectionViewCell.h"
#import "IVTKSYDianBoViewController.h"
static NSString *cellIdentifier = @"UICollectionViewCell";
@interface IVTMyLiveViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
{
NSArray *myLiveListArray;
UIImageView *myLiveImg;
UILabel *myLiveLabel;
UICollectionView *myCollectionView;
}
@end
@implementation IVTMyLiveViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavigationBar];
[self initUI];
myLiveListArray = [IVTAccountTool getMyLiveListArray];
if (myLiveListArray.count == 0) {
[HUDUtil showLoading];
[IVTAccountTool getMyLiveListRequestSuccess:^(NSArray *myLiveList) {
[HUDUtil hide];
myLiveListArray = myLiveList;
[myCollectionView reloadData];
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
}];
}
}
- (void)setNavigationBar{
self.navigationItem.title = @"我的直播";
}
- (void)initUI{
__unsafe_unretained typeof (self) wself = self;
myLiveImg = [[UIImageView alloc] init];
myLiveImg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"我的直播--背景条"]];
[self.view addSubview:myLiveImg];
[myLiveImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(wself.view).offset(5);
make.left.equalTo(wself.view).offset(0);
make.size.mas_equalTo(CGSizeMake(kScreenWidth, 40));
}];
myLiveLabel = [[UILabel alloc] init];
myLiveLabel.text = @"我的直播";
myLiveLabel.font = [UIFont YXFontOfSize:14];
myLiveLabel.textAlignment = NSTextAlignmentCenter;
myLiveLabel.textColor = [UIColor YXColorWithHexCode:@"#5A5A5A"];
[myLiveImg addSubview:myLiveLabel];
[myLiveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(myLiveImg).offset(5);
make.left.equalTo(myLiveImg).offset(0);
make.size.mas_equalTo(CGSizeMake(85, 30));
}];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
flowLayout.minimumLineSpacing = 3;
flowLayout.minimumInteritemSpacing = 1;
myCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
myCollectionView.backgroundColor = [UIColor clearColor];
myCollectionView.delegate = self;
myCollectionView.dataSource = self;
[myCollectionView registerClass:[IVTMyLiveCollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier];
[self.view addSubview:myCollectionView];
[myCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(myLiveImg.mas_bottom).offset(5);
make.left.equalTo(wself.view.mas_left);
make.right.equalTo(wself.view.mas_right);
make.bottom.equalTo(wself.view.mas_bottom);
}];
}
#pragma --mark UICollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return myLiveListArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
IVTMyLiveCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
NSString *urlString = [[myLiveListArray objectAtIndex:indexPath.row] valueForKey:@"thumbnail"];
cell.userHeaderImageUrl = urlString;
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section<[myLiveListArray count]) {
IVTKSYDianBoViewController *dianbo = [[IVTKSYDianBoViewController alloc]init];
dianbo.userId = [IVTAccountTool getUserId];
dianbo.roomInfo = myLiveListArray[indexPath.section];
[self.navigationController pushViewController:dianbo animated:YES];
}
// NSLog(@"当前点击的是%ld",indexPath.row);
}
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
#pragma mark --UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat itemWidth = (kScreenWidth - 24)/3;
return CGSizeMake(itemWidth, itemWidth);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 6, 0, 6);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end