-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMTwitterList.m
112 lines (72 loc) · 3.02 KB
/
CMTwitterList.m
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
//
// CMTwitterList.m
// CrystalMed
//
// Created by JAMES GUPTA on 06/09/2015.
// Copyright (c) 2015 AMEEHacks. All rights reserved.
//
#import "CMTwitterList.h"
#import <AFNetworking.h>
#import "CMTweetCell.h"
@implementation CMTwitterList
-(void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)filterPressed:(id)sender {
CMObjectListView *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"objectList"];
vc.delegate = self;
vc.className = @"Topics";
vc.mainKey = @"name";
// self.chosenIndexPath = indexPath;
[self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)pressedClose:(id)sender {
[self didCancel];
}
-(void)didSelectObject:(PFObject *)object {
self.chosenCategory = object;
// self.labelCategory.text = [object valueForKey:@"name"];
[self.navigationController popViewControllerAnimated:YES];
}
-(void)viewDidAppear:(BOOL)animated {
[self reloadData];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 103.0;
}
-(void)reloadData {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *str = nil;
if (self.chosenCategory) {
str = [self.chosenCategory valueForKey:@"hashtag"];
}
NSMutableArray *hashtags = [[NSMutableArray alloc]init];
[hashtags addObject:@"crystalmed"];
if ([str length] > 0) {
[hashtags addObject:str];
}
NSArray *array = [NSArray arrayWithArray:hashtags];
[manager GET:[NSString stringWithFormat:@"http://crystalmed.pythonanywhere.com/tweet"] parameters:@{@"hashtags": array} success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.tweets = [[NSArray alloc]initWithArray:responseObject];
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.tweets count];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CMTweetCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
NSDictionary *obj = [self.tweets objectAtIndex:indexPath.row];
cell.labelTweet.text = [obj valueForKey:@"text"];
[cell.profilePicture setImageWithURL:[NSURL URLWithString:[[obj objectForKey:@"user"]valueForKey:@"profile_image_url_https"]]placeholderImage:[UIImage imageNamed:@"placeHolder"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
}usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
return cell;
}
@end