-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnswersViewController.m
More file actions
73 lines (54 loc) · 1.98 KB
/
Copy pathAnswersViewController.m
File metadata and controls
73 lines (54 loc) · 1.98 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
//
// AnswersViewController.m
// StackOverflowDemoApp
//
// Created by Igor Nabokov on 26.01.16.
// Copyright © 2016 Igor Nabokov. All rights reserved.
//
#import "AnswersViewController.h"
@interface AnswersViewController ()
@end
@implementation AnswersViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.manager = [[StackOverflowManager alloc] init];
self.manager.answersDelegate = self;
[self.manager getAnswersByQuestion:self.sourceQuestion.question_id];
self.tableView.estimatedRowHeight = 100;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
- (void)answersReceivedWithResult:(NSArray *)result
{
self.answers = result;
[self.tableView reloadData];
}
- (void)answersFailedWithError:(NSError *)error
{
NSLog(@"Querying failed with error: %@", error);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.answers)
return self.answers.count;
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"answerCell" forIndexPath:indexPath];
Answer *answer = [self.answers objectAtIndex:indexPath.row];
NSString *html = answer.body;
NSAttributedString *htmlSource = [[NSAttributedString alloc]initWithData:[html dataUsingEncoding:NSUTF8StringEncoding]
options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
documentAttributes:NULL
error:NULL];
UILabel *answerLabel = [[cell.contentView subviews] objectAtIndex:0];
answerLabel.attributedText = htmlSource;
return cell;
}
@end