22
22
#import " TweetDetailViewController.h"
23
23
#import " CSTopicDetailVC.h"
24
24
#import " WebViewController.h"
25
+ #import " SVPullToRefresh.h"
26
+ #import " ODRefreshControl.h"
25
27
26
28
#define kCommentIndexNotFound -1
27
29
@@ -40,7 +42,7 @@ @interface CSTopicDetailVC ()<UITableViewDataSource,UITableViewDelegate,UIScroll
40
42
@property (nonatomic , strong ) User *commentToUser;
41
43
42
44
@property (nonatomic , assign ) NSInteger curIndex;
43
-
45
+ @property ( nonatomic , strong ) ODRefreshControl *refreshControl;
44
46
@end
45
47
46
48
@implementation CSTopicDetailVC {
@@ -50,35 +52,42 @@ @implementation CSTopicDetailVC{
50
52
- (void )viewDidLoad {
51
53
[super viewDidLoad ];
52
54
55
+ _curIndex = 0 ;
53
56
[self setupData ];
54
57
[self setupUI ];
55
-
56
- _curIndex = 0 ;
57
-
58
+ _refreshControl = [[ODRefreshControl alloc ] initInScrollView: self .myTableView];
59
+ [_refreshControl addTarget: self action: @selector ( refresh ) forControlEvents: UIControlEventValueChanged] ;
60
+
58
61
[self .myTableView reloadData ];
62
+ __weak typeof (self) weakSelf = self;
63
+ [self .myTableView addInfiniteScrollingWithActionHandler: ^{
64
+ [weakSelf sendRequestLoadMore: YES ];
65
+ }];
66
+ [self refresh ];
67
+ }
68
+
69
+ - (void )refresh {
59
70
[self refreshheader ];
60
71
[self refreshTopTweet ];
61
-
62
- dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC);
63
- dispatch_after (popTime, dispatch_get_main_queue (), ^{
64
- [self sendRequest ];
65
- });
66
-
72
+ [self sendRequestLoadMore: NO ];
67
73
}
68
74
69
- - (void )sendRequest {
75
+ - (void )sendRequestLoadMore : (BOOL )loadMore {
76
+ if (_curTweets.isLoading ) {
77
+ return ;
78
+ }
79
+ _curTweets.willLoadMore = loadMore;
80
+ _curTweets.isLoading = YES ;
70
81
__weak typeof (self) weakSelf = self;
71
-
72
- [[Coding_NetAPIManager sharedManager ] request_PublicTweetsWithTopic: _topicID andBlock: ^(NSArray *datalist, NSError *error) {
73
- NSMutableArray *list = [NSMutableArray array ];
74
- [datalist enumerateObjectsUsingBlock: ^(Tweet* obj, NSUInteger idx, BOOL *stop) {
75
- if (self.curTopWteet && [self .curTopWteet.id isEqualToNumber: obj.id ]) {
76
-
77
- }else {
78
- [list addObject: obj];
79
- }
80
- }];
81
- [weakSelf.curTweets configWithTweets: list];
82
+ NSNumber *last_id = nil ;
83
+ if (_curTweets.willLoadMore && _curTweets.list .count > 0 ) {
84
+ last_id = [(Tweet *)_curTweets.list.lastObject id ];
85
+ }
86
+ [[Coding_NetAPIManager sharedManager ] request_PublicTweetsWithTopic: _topicID last_id: last_id andBlock: ^(NSArray *datalist, NSError *error) {
87
+ [weakSelf.refreshControl endRefreshing ];
88
+ [weakSelf.myTableView.infiniteScrollingView stopAnimating ];
89
+ weakSelf.curTweets .isLoading = NO ;
90
+ [weakSelf.curTweets configWithTweets: datalist];
82
91
[weakSelf.myTableView reloadData ];
83
92
}];
84
93
}
@@ -297,9 +306,6 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
297
306
}
298
307
}
299
308
300
-
301
-
302
-
303
309
#pragma mark UIMessageInputViewDelegate
304
310
- (void )messageInputView : (UIMessageInputView *)inputView sendText : (NSString *)text {
305
311
[self sendCommentMessage: text];
@@ -408,31 +414,16 @@ - (void)setupData {
408
414
}
409
415
410
416
- (void )sendTweet {
411
- // __weak typeof(self) weakSelf = self;
417
+ __weak typeof (self) weakSelf = self;
412
418
TweetSendViewController *vc = [[TweetSendViewController alloc ] init ];
413
419
vc.sendNextTweet = ^(Tweet *nextTweet){
414
420
[nextTweet saveSendData ];// 发送前保存草稿
415
421
[[Coding_NetAPIManager sharedManager ] request_Tweet_DoTweet_WithObj: nextTweet andBlock: ^(id data, NSError *error) {
416
422
if (data) {
417
423
[Tweet deleteSendData ];// 发送成功后删除草稿
418
- // Tweets *curTweets = [weakSelf getCurTweets];
419
- // if (curTweets.tweetType != TweetTypePublicHot) {
420
- // Tweet *resultTweet = (Tweet *)data;
421
- // resultTweet.owner = [Login curLoginUser];
422
- // if (curTweets.list && [curTweets.list count] > 0) {
423
- // [curTweets.list insertObject:data atIndex:0];
424
- // }else{
425
- // curTweets.list = [NSMutableArray arrayWithObject:resultTweet];
426
- // }
427
- // [self.myTableView reloadData];
428
- // }
429
- // [weakSelf.view configBlankPage:EaseBlankPageTypeTweet hasData:(curTweets.list.count > 0) hasError:(error != nil) reloadButtonBlock:^(id sender) {
430
- // [weakSelf sendRequest];
431
- // }];
424
+ [weakSelf refresh ];
432
425
}
433
-
434
426
}];
435
-
436
427
};
437
428
UINavigationController *nav = [[BaseNavigationController alloc ] initWithRootViewController: vc];
438
429
[self .parentViewController presentViewController: nav animated: YES completion: nil ];
@@ -448,7 +439,7 @@ - (void)deleteTweet:(Tweet *)curTweet{
448
439
[_self.myTableView reloadData ];
449
440
[_self.view configBlankPage: ([[Login curLoginUser ] isSameToUser: _self.curTweets.curUser]? EaseBlankPageTypeTweet: EaseBlankPageTypeTweetOther) hasData: (_self.curTweets.list.count > 0 ) hasError: NO reloadButtonBlock: ^(id sender) {
450
441
ESStrongSelf;
451
- [_self sendRequest ];
442
+ [_self refresh ];
452
443
}];
453
444
}
454
445
}];
0 commit comments