From 9e6f8831480ca136de80b4fc82d788ab23380431 Mon Sep 17 00:00:00 2001 From: nvtu Date: Fri, 11 Aug 2017 15:00:15 +0700 Subject: [PATCH] Refactor and merge logic when request data for tableView in History screen, SNS main screen. Add refresh control, load more action --- LifeLog/LifeLog.xcodeproj/project.pbxproj | 6 ++ LifeLog/LifeLog/BaseTableViewController.h | 25 +++++++ LifeLog/LifeLog/BaseTableViewController.m | 120 ++++++++++++++++++++++++++++++ LifeLog/LifeLog/HistoryViewController.h | 7 +- LifeLog/LifeLog/HistoryViewController.m | 97 ++++++++++-------------- LifeLog/LifeLog/HistoryViewController.xib | 2 +- LifeLog/LifeLog/SNSViewController.h | 11 +-- LifeLog/LifeLog/SNSViewController.m | 79 ++------------------ LifeLog/LifeLog/SNSViewController.xib | 2 +- LifeLog/LifeLog/ServerAPI.h | 2 +- 10 files changed, 206 insertions(+), 145 deletions(-) create mode 100644 LifeLog/LifeLog/BaseTableViewController.h create mode 100644 LifeLog/LifeLog/BaseTableViewController.m diff --git a/LifeLog/LifeLog.xcodeproj/project.pbxproj b/LifeLog/LifeLog.xcodeproj/project.pbxproj index a60a697..10908c7 100644 --- a/LifeLog/LifeLog.xcodeproj/project.pbxproj +++ b/LifeLog/LifeLog.xcodeproj/project.pbxproj @@ -58,6 +58,7 @@ E99E13B11F33720600C78787 /* LabelCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E99E13AF1F33720600C78787 /* LabelCollectionViewCell.m */; }; E99E13B21F33720600C78787 /* LabelCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E99E13B01F33720600C78787 /* LabelCollectionViewCell.xib */; }; E9D909211F3D559D004CF99F /* TweetObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9D909201F3D559D004CF99F /* TweetObject.m */; }; + E9D909241F3D6E8C004CF99F /* BaseTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E9D909231F3D6E8C004CF99F /* BaseTableViewController.m */; }; E9F73DCC1F338A0F004A3A6F /* HistoryListTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E9F73DCA1F338A0F004A3A6F /* HistoryListTableViewCell.m */; }; E9F73DCD1F338A0F004A3A6F /* HistoryListTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E9F73DCB1F338A0F004A3A6F /* HistoryListTableViewCell.xib */; }; /* End PBXBuildFile section */ @@ -170,6 +171,8 @@ E99E13B01F33720600C78787 /* LabelCollectionViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LabelCollectionViewCell.xib; sourceTree = ""; }; E9D9091F1F3D559D004CF99F /* TweetObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TweetObject.h; sourceTree = ""; }; E9D909201F3D559D004CF99F /* TweetObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TweetObject.m; sourceTree = ""; }; + E9D909221F3D6E8C004CF99F /* BaseTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseTableViewController.h; sourceTree = ""; }; + E9D909231F3D6E8C004CF99F /* BaseTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseTableViewController.m; sourceTree = ""; }; E9F73DC91F338A0F004A3A6F /* HistoryListTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HistoryListTableViewCell.h; sourceTree = ""; }; E9F73DCA1F338A0F004A3A6F /* HistoryListTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HistoryListTableViewCell.m; sourceTree = ""; }; E9F73DCB1F338A0F004A3A6F /* HistoryListTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HistoryListTableViewCell.xib; sourceTree = ""; }; @@ -469,6 +472,8 @@ 9CBDA0F91F2ECE2C0055DED1 /* BaseViewController.m */, 6E48AF0B1F2F9D3200C1D184 /* CustomTextField.h */, 6E48AF0C1F2F9D3200C1D184 /* CustomTextField.m */, + E9D909221F3D6E8C004CF99F /* BaseTableViewController.h */, + E9D909231F3D6E8C004CF99F /* BaseTableViewController.m */, ); name = BaseViewController; sourceTree = ""; @@ -752,6 +757,7 @@ 6E18CEDC1F2E40F50029891F /* User.m in Sources */, 6ECC40711F2A5FEB00AAEB97 /* NSDate+helper.m in Sources */, 6E18CED31F2E39DB0029891F /* LoginViewController.m in Sources */, + E9D909241F3D6E8C004CF99F /* BaseTableViewController.m in Sources */, 6E84E3761F27A701001EB88E /* main.m in Sources */, 6E84E3B51F27A98B001EB88E /* HistoryViewController.m in Sources */, E9373E4D1F361A230059355A /* HistoryGraphObject.m in Sources */, diff --git a/LifeLog/LifeLog/BaseTableViewController.h b/LifeLog/LifeLog/BaseTableViewController.h new file mode 100644 index 0000000..56f0712 --- /dev/null +++ b/LifeLog/LifeLog/BaseTableViewController.h @@ -0,0 +1,25 @@ +// +// BaseTableViewController.h +// LifeLog +// +// Created by nvtu on 8/11/17. +// Copyright © 2017 PhongNV. All rights reserved. +// + +#import + +@interface BaseTableViewController : UIViewController { + NSMutableArray * _curDataList; + BOOL _firstTime; + BOOL _isLoading; + BOOL _isEndOfResult; + int _curPage; +} + +@property (weak, nonatomic) IBOutlet UITableView *tableBase; +@property (strong, nonatomic) UIRefreshControl *refreshControl; + +-(void) callRequestToUpdateData; +-(void) updateTableData : (NSArray *) array error: (NSError *) error; +-(void) resetData; +@end diff --git a/LifeLog/LifeLog/BaseTableViewController.m b/LifeLog/LifeLog/BaseTableViewController.m new file mode 100644 index 0000000..08ae3ab --- /dev/null +++ b/LifeLog/LifeLog/BaseTableViewController.m @@ -0,0 +1,120 @@ +// +// BaseTableViewController.m +// LifeLog +// +// Created by nvtu on 8/11/17. +// Copyright © 2017 PhongNV. All rights reserved. +// + +#import "BaseTableViewController.h" +#import "Utilities.h" + +@interface BaseTableViewController () + +@end + +@implementation BaseTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + _firstTime = false; + _curPage = 1; + _isEndOfResult = false; + _curDataList = [[NSMutableArray alloc] init]; + self.refreshControl = [[UIRefreshControl alloc] init]; + [self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged]; + [self.tableBase addSubview:self.refreshControl]; + // Do any additional setup after loading the view. +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +-(void) callRequestToUpdateData { + _isLoading = true; +} + +-(void) resetData { + _isLoading = false; + _isEndOfResult = false; + _firstTime = false; + _curPage = 1; + [_curDataList removeAllObjects]; + [self.tableBase reloadData]; + [self callRequestToUpdateData]; +} + +-(void) refreshTable { + [self resetData]; +} + +-(void) updateTableData : (NSArray *) array error: (NSError *) error { + BaseTableViewController __weak *weakSelf = self; + _isLoading = false; + _firstTime = true; + if(self.refreshControl != nil) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.refreshControl endRefreshing]; + }); + } + if(error == nil) { + if(array.count != 0) { + [_curDataList addObjectsFromArray:array]; + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf.tableBase reloadData]; + }); + } + else { + if(_curPage != 1) { + _isEndOfResult = true; + _curPage -= 1; + } + else { + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf.tableBase reloadData]; + }); + } + } + } + else { + _curPage = MAX(1, _curPage - 1); + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *message = [error.userInfo objectForKey:@"message"]; + [Utilities showErrorMessage:message withViewController:weakSelf]; + }); + } +} + +#pragma mark UITableView Delegate +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + if((_curDataList == nil || _curDataList.count == 0) && _firstTime) { + UILabel * noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)]; + noDataLabel.text = @"No data available"; + noDataLabel.backgroundColor = [UIColor clearColor]; + noDataLabel.textColor = [UIColor whiteColor]; + noDataLabel.textAlignment = NSTextAlignmentCenter; + tableView.backgroundView = noDataLabel; + tableView.backgroundView.layer.zPosition -= 1; + return 0; + } + tableView.backgroundView = nil; + return 1; +} + +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return _curDataList.count; +} + +- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { + NSInteger lastRowIndex = [tableView numberOfRowsInSection:0] - 1; + if (indexPath.row == lastRowIndex) { + // This is the last cell + if(!_isLoading) { + _curPage += 1; + [self callRequestToUpdateData]; + } + } +} +@end diff --git a/LifeLog/LifeLog/HistoryViewController.h b/LifeLog/LifeLog/HistoryViewController.h index a099807..62eea48 100644 --- a/LifeLog/LifeLog/HistoryViewController.h +++ b/LifeLog/LifeLog/HistoryViewController.h @@ -9,17 +9,15 @@ #import #import +#import "BaseTableViewController.h" #import "CollectionView.h" #import "Entities.h" -@interface HistoryViewController : UIViewController { +@interface HistoryViewController : BaseTableViewController { NSDate * _curDate; HistoryObject * _curHisObj; HistoryGraphObject * _curHisGraphObj; - NSMutableArray * _curHisList; - - int _curPageIndex; } @property (weak, nonatomic) IBOutlet UILabel *lblCircleStep; @@ -38,7 +36,6 @@ @property (weak, nonatomic) IBOutlet BarChartView *viewBarChart; -@property (weak, nonatomic) IBOutlet UITableView *tableListHistory; @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; - (IBAction)swipeAction:(UISwipeGestureRecognizer *)sender; diff --git a/LifeLog/LifeLog/HistoryViewController.m b/LifeLog/LifeLog/HistoryViewController.m index 6147f6b..96a4d79 100644 --- a/LifeLog/LifeLog/HistoryViewController.m +++ b/LifeLog/LifeLog/HistoryViewController.m @@ -27,12 +27,11 @@ [self setupChartView]; _curDate = [NSDate date]; - _curHisList = [[NSMutableArray alloc] init]; - [self callRequestToUpdateData]; + [self checkRequestData]; //register nib for table view - [self.tableListHistory registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; + [self.tableBase registerNib:[UINib nibWithNibName:@"HistoryListTableViewCell" bundle:nil] forCellReuseIdentifier:@"HistoryListCell"]; } - (void)viewDidAppear:(BOOL) animated @@ -55,7 +54,7 @@ [self.viewCollectionType setSpacing:2]; [self.viewCollectionType setArrayTitle:typeTitle]; self.viewCollectionType.changeCurrentIndex = ^(int index){ - [self callRequestToUpdateData]; + [self checkRequestData]; }; NSArray *modeTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.mode.1", nil), NSLocalizedString(@"lifelog.history.mode.2", nil), NSLocalizedString(@"lifelog.history.mode.3", nil), nil]; @@ -65,7 +64,7 @@ [self.viewCollectionMode setNormalColor:[Utilities convertHecToColor:0x191919] highlightColor:[Utilities convertHecToColor:0x474747] textColor:[UIColor whiteColor]]; [self.viewCollectionMode setArrayTitle:modeTitle]; self.viewCollectionMode.changeCurrentIndex = ^(int index){ - [self callRequestToUpdateData]; + [self checkRequestData]; }; NSArray *shareTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.share.1", nil), NSLocalizedString(@"lifelog.history.share.2", nil), NSLocalizedString(@"lifelog.history.share.3", nil), NSLocalizedString(@"lifelog.history.share.4", nil), NSLocalizedString(@"lifelog.history.share.5", nil), nil]; @@ -75,10 +74,10 @@ [self.viewCollectionShare disableSelection]; //add tap gesture for enable tap on gesture on CollectionView in ScrollView - UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; - [recognizer setNumberOfTapsRequired:1]; - self.scrollView.userInteractionEnabled = YES; - [self.scrollView addGestureRecognizer:recognizer]; +// UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; +// [recognizer setNumberOfTapsRequired:1]; +// self.scrollView.userInteractionEnabled = YES; +// [self.scrollView addGestureRecognizer:recognizer]; } - (void)setupChartView { @@ -141,13 +140,12 @@ } } --(void) callRequestToUpdateData { - MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; - NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; - int type = self.viewCollectionType.getCurrentIndex; - int mode = self.viewCollectionMode.getCurrentIndex + 1; - - if(self.tableListHistory.alpha == 0.0) { +-(void) checkRequestData { + if(self.tableBase.alpha == 0.0) { + NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; + int type = self.viewCollectionType.getCurrentIndex; + int mode = self.viewCollectionMode.getCurrentIndex + 1; + MBProgressHUD *hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; [[ServerAPI server] requestHistory:token atDate:_curDate withType:type andMode:mode CompletionHandler:^(HistoryObject *object, NSError *error) { HistoryViewController __weak *weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ @@ -186,37 +184,39 @@ }]; } else { - [[ServerAPI server] requestHistoryList:token withType:type andMode:mode AtPage:1 CompletionHandler:^(NSMutableArray *object, NSError *error) { - HistoryViewController __weak *weakSelf = self; - dispatch_async(dispatch_get_main_queue(), ^{ - if(hudView != nil) { - [hudView hideAnimated:true]; - } - }); - if(error == nil) { - _curHisList = object; - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf.tableListHistory reloadData]; - }); - } - else { - dispatch_async(dispatch_get_main_queue(), ^{ - NSString *message = [error.userInfo objectForKey:@"message"]; - [Utilities showErrorMessage:message withViewController:weakSelf]; - }); - } - }]; + [self resetData]; + } +} + +-(void) callRequestToUpdateData { + [super callRequestToUpdateData]; + NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; + int type = self.viewCollectionType.getCurrentIndex; + int mode = self.viewCollectionMode.getCurrentIndex + 1; + + MBProgressHUD *hudView = nil; + if(_curPage == 1 && !self.refreshControl.isRefreshing) { + hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; } + [[ServerAPI server] requestHistoryList:token withType:type andMode:mode AtPage:_curPage CompletionHandler:^(NSArray *array, NSError *error) { + dispatch_async(dispatch_get_main_queue(), ^{ + if(hudView != nil) { + [hudView hideAnimated:true]; + } + }); + HistoryViewController __weak *weakSelf = self; + [weakSelf updateTableData:array error:error]; + }]; } #pragma mark IBAction -(void) swipeAction:(UISwipeGestureRecognizer *)sender { bool alphaValue = self.scrollView.alpha == 1.0 ? 1.0 : 0.0; [UIView animateWithDuration:0.5 animations:^{ - self.tableListHistory.alpha = alphaValue; + self.tableBase.alpha = alphaValue; self.scrollView.alpha = 1.0 - alphaValue; } completion:^(BOOL completed) { - [self callRequestToUpdateData]; + [self checkRequestData]; }]; } @@ -247,28 +247,9 @@ } #pragma mark UITableView Delegate -- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { - if(_curHisList == nil || _curHisList.count == 0) { - UILabel * noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)]; - noDataLabel.text = @"No data available"; - noDataLabel.backgroundColor = [UIColor clearColor]; - noDataLabel.textColor = [UIColor whiteColor]; - noDataLabel.textAlignment = NSTextAlignmentCenter; - tableView.backgroundView = noDataLabel; - tableView.backgroundView.layer.zPosition -= 1; - return 0; - } - tableView.backgroundView = nil; - return 1; -} - -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return _curHisList.count; -} - - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HistoryListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryListCell"]; - HistoryObject * obj = [_curHisList objectAtIndex:indexPath.row]; + HistoryObject * obj = [_curDataList objectAtIndex:indexPath.row]; cell.lblStep.text = [NSString stringWithFormat:@"%d", obj.step]; cell.lblPower.text = [NSString stringWithFormat:@"%0.2f", obj.calories]; cell.lblDistance.text = [NSString stringWithFormat:@"%0.1f", obj.distance]; diff --git a/LifeLog/LifeLog/HistoryViewController.xib b/LifeLog/LifeLog/HistoryViewController.xib index 55a716b..42ee58d 100644 --- a/LifeLog/LifeLog/HistoryViewController.xib +++ b/LifeLog/LifeLog/HistoryViewController.xib @@ -20,7 +20,7 @@ - + diff --git a/LifeLog/LifeLog/SNSViewController.h b/LifeLog/LifeLog/SNSViewController.h index 74cec36..9c45a47 100644 --- a/LifeLog/LifeLog/SNSViewController.h +++ b/LifeLog/LifeLog/SNSViewController.h @@ -7,15 +7,10 @@ // #import +#import "BaseTableViewController.h" -@interface SNSViewController : UIViewController { - BOOL _firstTime; - BOOL _isLoading; - BOOL _isEndOfResult; - int _curPage; - NSMutableArray * _curTweetList; -} +@interface SNSViewController : BaseTableViewController { -@property (weak, nonatomic) IBOutlet UITableView *tableRecent; +} @end diff --git a/LifeLog/LifeLog/SNSViewController.m b/LifeLog/LifeLog/SNSViewController.m index bfc4844..6aff798 100644 --- a/LifeLog/LifeLog/SNSViewController.m +++ b/LifeLog/LifeLog/SNSViewController.m @@ -22,16 +22,11 @@ [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.title = NSLocalizedString(@"lifelog.tapbar.sns", nil); - _firstTime = true; - _curPage = 1; - _isEndOfResult = false; - - _curTweetList = [[NSMutableArray alloc] init]; - + [self callRequestToUpdateData]; //register nib for table view - [self.tableRecent registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; + [self.tableBase registerNib:[UINib nibWithNibName:@"SNSRecentTopicTableViewCell" bundle:nil] forCellReuseIdentifier:@"RecentTopicCell"]; } - (void)didReceiveMemoryWarning { @@ -41,28 +36,9 @@ #pragma mark UITableView Delegate -- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { - if((_curTweetList == nil || _curTweetList.count == 0) && !_firstTime) { - UILabel * noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.frame.size.height)]; - noDataLabel.text = @"No data available"; - noDataLabel.backgroundColor = [UIColor clearColor]; - noDataLabel.textColor = [UIColor whiteColor]; - noDataLabel.textAlignment = NSTextAlignmentCenter; - tableView.backgroundView = noDataLabel; - tableView.backgroundView.layer.zPosition -= 1; - return 0; - } - tableView.backgroundView = nil; - return 1; -} - -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return _curTweetList.count; -} - - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { SNSRecentTopicTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"RecentTopicCell"]; - TweetObject *object = [_curTweetList objectAtIndex:indexPath.row]; + TweetObject *object = [_curDataList objectAtIndex:indexPath.row]; if(object.avatarLink && ![object.avatarLink isKindOfClass:[NSNull class]]) { [cell.imgAvatar sd_setImageWithURL:[NSURL URLWithString:[Utilities getImageLink:object.avatarLink]]]; } @@ -75,64 +51,25 @@ return cell; } -- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { - NSInteger lastRowIndex = [tableView numberOfRowsInSection:0] - 1; - if (indexPath.row == lastRowIndex) { - // This is the last cell - if(!_isLoading) { - _curPage += 1; - [self callRequestToUpdateData]; - } - } -} #pragma mark Private Function -(void) callRequestToUpdateData { - _isLoading = true; + [super callRequestToUpdateData]; + NSString * token = [[NSUserDefaults standardUserDefaults] stringForKey:kToken]; MBProgressHUD *hudView = nil; - if(_curPage == 1) { + if(_curPage == 1 && !self.refreshControl.isRefreshing) { hudView = [MBProgressHUD showHUDAddedTo:self.view animated:true]; } [[ServerAPI server] requestRecentlyTweetsList:token withPage:_curPage CompletionHandler:^(NSArray *array, NSError *error){ - SNSViewController __weak *weakSelf = self; - _isLoading = false; dispatch_async(dispatch_get_main_queue(), ^{ if(hudView != nil) { [hudView hideAnimated:true]; } }); - if(error == nil) { - if(_curPage == 1) { - [_curTweetList removeAllObjects]; - } - if(array.count != 0) { - [_curTweetList addObjectsFromArray:array]; - dispatch_async(dispatch_get_main_queue(), ^{ - [weakSelf.tableRecent reloadData]; - }); - } - else { - _isEndOfResult = true; - _curPage = MAX(1, _curPage - 1); - } - } - else { - _curPage = MAX(1, _curPage - 1); - dispatch_async(dispatch_get_main_queue(), ^{ - NSString *message = [error.userInfo objectForKey:@"message"]; - [Utilities showErrorMessage:message withViewController:weakSelf]; - }); - } - + SNSViewController __weak *weakSelf = self; + [weakSelf updateTableData:array error:error]; }]; } --(void) resetData { - _isLoading = false; - _isEndOfResult = false; - _firstTime = true; - _curPage = 1; -} - @end diff --git a/LifeLog/LifeLog/SNSViewController.xib b/LifeLog/LifeLog/SNSViewController.xib index aa6a4b4..4ce2961 100644 --- a/LifeLog/LifeLog/SNSViewController.xib +++ b/LifeLog/LifeLog/SNSViewController.xib @@ -10,7 +10,7 @@ - + diff --git a/LifeLog/LifeLog/ServerAPI.h b/LifeLog/LifeLog/ServerAPI.h index 8c63ef2..264b18e 100644 --- a/LifeLog/LifeLog/ServerAPI.h +++ b/LifeLog/LifeLog/ServerAPI.h @@ -25,7 +25,7 @@ extern NSString *const kToken; #pragma mark - History Screen Function - (void) requestHistory:(NSString *)token atDate:(NSDate *)date withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryObject *, NSError *)) completion; - (void) requestHistoryGraph:(NSString *)token withType:(int)type andMode:(int) mode CompletionHandler:(void (^)(HistoryGraphObject *, NSError *)) completion; -- (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSMutableArray *, NSError *)) completion; +- (void) requestHistoryList:(NSString *)token withType:(int)type andMode:(int) mode AtPage:(int) page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; #pragma mark - SNS Screen Function - (void) requestRecentlyTweetsList:(NSString *)token withPage:(int)page CompletionHandler:(void (^)(NSArray *, NSError *)) completion; -- 1.8.5.3