Skip to content

Commit

Permalink
proxy更改,避免循环引用
Browse files Browse the repository at this point in the history
  • Loading branch information
tbl00c committed Sep 26, 2016
1 parent 9fba0ca commit 50f55da
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
//

#import "TLMomentsViewController+Proxy.h"
#import "TLMomentsProxy.h"

@implementation TLMomentsViewController (Proxy)

- (void)loadData
{
self.data = [NSMutableArray arrayWithArray:self.proxy.testData];
TLMomentsProxy *proxy = [[TLMomentsProxy alloc] init];
self.data = [NSMutableArray arrayWithArray:proxy.testData];
[self.tableView reloadData];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
//

#import "TLTableViewController.h"
#import "TLMomentsProxy.h"

@interface TLMomentsViewController : TLTableViewController

@property (nonatomic, strong) NSMutableArray *data;

@property (nonatomic, strong) TLMomentsProxy *proxy;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,4 @@ - (void)viewDidLoad {
[self loadData];
}

#pragma mark - # Getter
- (TLMomentsProxy *)proxy
{
if (_proxy == nil) {
_proxy = [[TLMomentsProxy alloc] init];
}
return _proxy;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "TLExpressionChosenViewController+Proxy.h"
#import "TLExpressionProxy.h"
#import <MJRefresh.h>

@implementation TLExpressionChosenViewController (Proxy)
Expand All @@ -17,11 +18,11 @@ - (void)loadDataWithLoadingView:(BOOL)showLoadingView
[SVProgressHUD show];
}
kPageIndex = 1;
__weak typeof(self) weakSelf = self;
[self.proxy requestExpressionChosenListByPageIndex:kPageIndex success:^(id data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionChosenListByPageIndex:kPageIndex success:^(id data) {
[SVProgressHUD dismiss];
kPageIndex ++;
weakSelf.data = [[NSMutableArray alloc] init];
self.data = [[NSMutableArray alloc] init];
for (TLEmojiGroup *group in data) { // 优先使用本地表情
TLEmojiGroup *localEmojiGroup = [[TLExpressionHelper sharedHelper] emojiGroupByID:group.groupID];
if (localEmojiGroup) {
Expand All @@ -31,12 +32,12 @@ - (void)loadDataWithLoadingView:(BOOL)showLoadingView
[self.data addObject:group];
}
}
[weakSelf.tableView reloadData];
[self.tableView reloadData];
} failure:^(NSString *error) {
[SVProgressHUD dismiss];
}];

[self.proxy requestExpressionChosenBannerSuccess:^(id data) {
[proxy requestExpressionChosenBannerSuccess:^(id data) {
self.bannerData = data;
[self.tableView reloadData];
} failure:^(NSString *error) {
Expand All @@ -46,8 +47,8 @@ - (void)loadDataWithLoadingView:(BOOL)showLoadingView

- (void)loadMoreData
{
__weak typeof(self) weakSelf = self;
[self.proxy requestExpressionChosenListByPageIndex:kPageIndex success:^(NSMutableArray *data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionChosenListByPageIndex:kPageIndex success:^(NSMutableArray *data) {
[SVProgressHUD dismiss];
if (data.count == 0) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
Expand All @@ -64,7 +65,7 @@ - (void)loadMoreData
[self.data addObject:group];
}
}
[weakSelf.tableView reloadData];
[self.tableView reloadData];
}
} failure:^(NSString *error) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "TLExpressionChosenViewController+TableView.h"
#import "TLExpressionDetailViewController.h"
#import "TLExpressionHelper.h"
#import "TLExpressionProxy.h"

@implementation TLExpressionChosenViewController (TableView)

Expand Down Expand Up @@ -86,7 +87,8 @@ - (void)expressionBannerCellDidSelectBanner:(id)item
- (void)expressionCellDownloadButtonDown:(TLEmojiGroup *)group
{
group.status = TLEmojiGroupStatusDownloading;
[self.proxy requestExpressionGroupDetailByGroupID:group.groupID pageIndex:1 success:^(id data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionGroupDetailByGroupID:group.groupID pageIndex:1 success:^(id data) {
group.data = data;
[[TLExpressionHelper sharedHelper] downloadExpressionsWithGroupInfo:group progress:^(CGFloat progress) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import "TLTableViewController.h"
#import "TLExpressionHelper.h"
#import "TLExpressionProxy.h"

@interface TLExpressionChosenViewController : TLTableViewController
{
Expand All @@ -19,7 +18,5 @@

@property (nonatomic, strong) NSArray *bannerData;

@property (nonatomic, strong) TLExpressionProxy *proxy;


@end
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ - (void)viewDidDisappear:(BOOL)animated
}

#pragma mark - # Getter
- (TLExpressionProxy *)proxy
{
if (_proxy == nil) {
_proxy = [[TLExpressionProxy alloc] init];
}
return _proxy;
}

- (TLSearchController *)searchController
{
if (_searchController == nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ @interface TLExpressionDetailViewController ()
NSInteger kPageIndex;
}

@property (nonatomic, strong) TLExpressionProxy *proxy;

@end

@implementation TLExpressionDetailViewController
Expand Down Expand Up @@ -61,25 +59,17 @@ - (void)setGroup:(TLEmojiGroup *)group
- (void)p_loadData
{
kPageIndex = 1;
__weak typeof(self) weakSelf = self;
[self.proxy requestExpressionGroupDetailByGroupID:self.group.groupID pageIndex:kPageIndex success:^(id data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionGroupDetailByGroupID:self.group.groupID pageIndex:kPageIndex success:^(id data) {
[SVProgressHUD dismiss];
weakSelf.group.data = data;
[weakSelf.collectionView reloadData];
self.group.data = data;
[self.collectionView reloadData];
} failure:^(NSString *error) {
[SVProgressHUD dismiss];
}];
}

#pragma mark - # Getter
- (TLExpressionProxy *)proxy
{
if (_proxy == nil) {
_proxy = [[TLExpressionProxy alloc] init];
}
return _proxy;
}

- (UICollectionView *)collectionView
{
if (_collectionView == nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "TLExpressionPublicViewController+Proxy.h"
#import "TLExpressionHelper.h"
#import "TLExpressionProxy.h"
#import <MJRefresh.h>

@implementation TLExpressionPublicViewController (Proxy)
Expand All @@ -18,11 +19,11 @@ - (void)loadDataWithLoadingView:(BOOL)showLoadingView
[SVProgressHUD show];
}
kPageIndex = 1;
__weak typeof(self) weakSelf = self;
[self.proxy requestExpressionPublicListByPageIndex:kPageIndex success:^(id data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionPublicListByPageIndex:kPageIndex success:^(id data) {
[SVProgressHUD dismiss];
kPageIndex ++;
weakSelf.data = [[NSMutableArray alloc] init];
self.data = [[NSMutableArray alloc] init];
for (TLEmojiGroup *group in data) { // 优先使用本地表情
TLEmojiGroup *localEmojiGroup = [[TLExpressionHelper sharedHelper] emojiGroupByID:group.groupID];
if (localEmojiGroup) {
Expand All @@ -32,16 +33,16 @@ - (void)loadDataWithLoadingView:(BOOL)showLoadingView
[self.data addObject:group];
}
}
[weakSelf.collectionView reloadData];
[self.collectionView reloadData];
} failure:^(NSString *error) {
[SVProgressHUD dismiss];
}];
}

- (void)loadMoreData
{
__weak typeof(self) weakSelf = self;
[self.proxy requestExpressionPublicListByPageIndex:kPageIndex success:^(NSMutableArray *data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionPublicListByPageIndex:kPageIndex success:^(NSMutableArray *data) {
[SVProgressHUD dismiss];
if (data.count == 0) {
[self.collectionView.mj_footer endRefreshingWithNoMoreData];
Expand All @@ -58,7 +59,7 @@ - (void)loadMoreData
[self.data addObject:group];
}
}
[weakSelf.collectionView reloadData];
[self.collectionView reloadData];
}
} failure:^(NSString *error) {
[self.collectionView.mj_footer endRefreshingWithNoMoreData];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "TLViewController.h"
#import "TLExpressionProxy.h"

@interface TLExpressionPublicViewController : TLViewController
{
Expand All @@ -16,8 +15,6 @@

@property (nonatomic, strong) NSMutableArray *data;

@property (nonatomic, strong) TLExpressionProxy *proxy;

@property (nonatomic, strong) UICollectionView *collectionView;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ - (TLExpressionSearchViewController *)searchVC
return _searchVC;
}

- (TLExpressionProxy *)proxy
{
if (_proxy == nil) {
_proxy = [[TLExpressionProxy alloc] init];
}
return _proxy;
}

- (UICollectionView *)collectionView
{
if (_collectionView == nil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

@interface TLExpressionSearchViewController () <TLExpressionCellDelegate>

@property (nonatomic, strong) TLExpressionProxy *proxy;

@property (nonatomic, strong) NSArray *data;

@end
Expand Down Expand Up @@ -90,7 +88,8 @@ - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
NSString *keyword = searchBar.text;
if (keyword.length > 0) {
[SVProgressHUD show];
[self.proxy requestExpressionSearchByKeyword:keyword success:^(NSArray *data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionSearchByKeyword:keyword success:^(NSArray *data) {
self.data = data;
[self.tableView reloadData];
[SVProgressHUD dismiss];
Expand All @@ -106,7 +105,8 @@ - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- (void)expressionCellDownloadButtonDown:(TLEmojiGroup *)group
{
group.status = TLEmojiGroupStatusDownloading;
[self.proxy requestExpressionGroupDetailByGroupID:group.groupID pageIndex:1 success:^(id data) {
TLExpressionProxy *proxy = [[TLExpressionProxy alloc] init];
[proxy requestExpressionGroupDetailByGroupID:group.groupID pageIndex:1 success:^(id data) {
group.data = data;
[[TLExpressionHelper sharedHelper] downloadExpressionsWithGroupInfo:group progress:^(CGFloat progress) {

Expand Down Expand Up @@ -134,13 +134,4 @@ - (void)updateSearchResultsForSearchController:(UISearchController *)searchContr

}

#pragma mark - # Getter
- (TLExpressionProxy *)proxy
{
if (_proxy == nil) {
_proxy = [[TLExpressionProxy alloc] init];
}
return _proxy;
}

@end

0 comments on commit 50f55da

Please sign in to comment.