forked from coding/Coding-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLikersViewController.m
More file actions
executable file
·140 lines (116 loc) · 4.35 KB
/
LikersViewController.m
File metadata and controls
executable file
·140 lines (116 loc) · 4.35 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
//
// LikersViewController.m
// Coding_iOS
//
// Created by 王 原闯 on 14-9-4.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "LikersViewController.h"
#import "ODRefreshControl.h"
#import "User.h"
#import "Coding_NetAPIManager.h"
#import "UserCell.h"
#import "ConversationViewController.h"
#import "UserInfoViewController.h"
@interface LikersViewController ()
@property (strong, nonatomic) NSArray *like_reward_users;
@property (strong, nonatomic) UITableView *myTableView;
@property (strong, nonatomic) ODRefreshControl *myRefreshControl;
@property (strong, nonatomic) NSMutableArray *searchResults;
@end
@implementation LikersViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"赞赏的人";
_myTableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
tableView.backgroundColor = [UIColor clearColor];
[tableView registerClass:[UserCell class] forCellReuseIdentifier:kCellIdentifier_UserCell];
tableView.delegate = self;
tableView.dataSource = self;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
tableView;
});
_myRefreshControl = [[ODRefreshControl alloc] initInScrollView:self.myTableView];
[_myRefreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[self refresh];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)refresh{
if (_curTweet.isLoading) {
return;
}
if (_like_reward_users.count <= 0) {
[self.view beginLoading];
}
__weak typeof(self) weakSelf = self;
[[Coding_NetAPIManager sharedManager] request_Tweet_LikesAndRewards_WithObj:_curTweet andBlock:^(id data, NSError *error) {
[weakSelf.view endLoading];
[weakSelf.myRefreshControl endRefreshing];
if ([data isKindOfClass:[NSDictionary class]]) {
[weakSelf refreshWithData:data];
}
}];
}
- (void)refreshWithData:(NSDictionary *)data{
if (data[@"likeUsers"]) {
_curTweet.like_users = [NSObject arrayFromJSON:data[@"likeUsers"] ofObjects:@"User"];
}
if (data[@"rewardUsers"]) {
_curTweet.reward_users = [NSObject arrayFromJSON:data[@"rewardUsers"] ofObjects:@"User"];
}
_like_reward_users = [_curTweet like_reward_users];
[self.myTableView reloadData];
}
#pragma mark Table M
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (_like_reward_users) {
return [_like_reward_users count];
}else{
return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UserCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_UserCell forIndexPath:indexPath];
cell.userIconView.layer.borderColor = [UIColor colorWithHexString:@"0xFFAE03"].CGColor;
User *curUser = [_like_reward_users objectAtIndex:indexPath.row];
cell.curUser = curUser;
cell.usersType = UsersTypeTweetLikers;
cell.userIconView.layer.borderWidth = [_curTweet rewardedBy:curUser]? 1.0: 0;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:60];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [UserCell cellHeight];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
User *user = [_like_reward_users objectAtIndex:indexPath.row];
UserInfoViewController *vc = [[UserInfoViewController alloc] init];
vc.curUser = user;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)dealloc
{
_myTableView.delegate = nil;
_myTableView.dataSource = nil;
}
@end