Skip to content

Commit

Permalink
Add Refreshing example to emotion tableView controller. fix the XHRef…
Browse files Browse the repository at this point in the history
…reshControl ending load more bug.
  • Loading branch information
xhzengAIB committed Jun 9, 2014
1 parent 1e919b5 commit a0675ef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,11 @@ - (void)addContactForGroup {
#pragma mark - DataSource

- (void)loadDataSource {
self.isDataLoading = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSMutableArray *dataSource = [[NSMutableArray alloc] initWithObjects:@"华捷新闻,点击查看美女新闻呢!", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"点进入聊天页面,这里有多种显示样式", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", @"请问你现在在哪里啊?我在广州天河", @"请问你现在在哪里啊?我在广州天河", @"请问你现在在哪里啊?我在广州天河", @"请问你现在在哪里啊?我在广州天河", @"请问你现在在哪里啊?我在广州天河", @"点击我查看最新消息,里面有惊喜哦!", @"点击我查看最新消息,里面有惊喜哦!", nil];
sleep(2);
dispatch_async(dispatch_get_main_queue(), ^{
self.isDataLoading = NO;
self.dataSource = dataSource;
[self.tableView reloadData];
[self endPullDownRefreshing];
});
});
}
Expand All @@ -206,7 +202,6 @@ - (void)loadDataSource {

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self startPullDownRefreshing];
}

- (void)viewDidLoad {
Expand All @@ -216,6 +211,8 @@ - (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showMenuOnView:)];

[self.view addSubview:self.tableView];

[self loadDataSource];
}

- (void)didReceiveMemoryWarning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved.
//

#import "XHBaseTableViewController.h"
#import "XHPullRefreshTableViewController.h"

@interface XHMoreExpressionShopsTableViewController : XHBaseTableViewController
@interface XHMoreExpressionShopsTableViewController : XHPullRefreshTableViewController

@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,29 @@ @interface XHMoreExpressionShopsTableViewController ()
@implementation XHMoreExpressionShopsTableViewController

- (void)loadDataSource {
self.dataSource = (NSMutableArray *)@[@"emotionShopOne", @"emotionShopOne", @"emotionShopOne", @"emotionShopOne", @"emotionShopTwo", @"emotionShopOther", @"emotionShopTwo", @"", @"emotionShopTwo", @"emotionShopOther", @"emotionShopOne", @"emotionShopOther", @"emotionShopTwo", @"emotionShopOne", @"emotionShopTwo"];
self.isDataLoading = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
sleep(1);
NSMutableArray *dataSource = [NSMutableArray arrayWithArray:@[@"emotionShopOne", @"emotionShopOne", @"emotionShopOne", @"emotionShopOne", @"emotionShopTwo", @"emotionShopOther", @"emotionShopTwo", @"", @"emotionShopTwo", @"emotionShopOther", @"emotionShopOne", @"emotionShopOther", @"emotionShopTwo", @"emotionShopOne", @"emotionShopTwo"]];

dispatch_async(dispatch_get_main_queue(), ^{
self.isDataLoading = NO;
if (self.requestCurrentPage) {
NSMutableArray *indexPaths = [NSMutableArray array];
[dataSource enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[indexPaths addObject:[NSIndexPath indexPathForRow:self.dataSource.count + idx inSection:0]];
}];

[self.dataSource addObjectsFromArray:dataSource];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
[self endLoadMoreRefreshing];
} else {
self.dataSource = dataSource;
[self.tableView reloadData];
[self endPullDownRefreshing];
}
});
});
}

#pragma mark - Propertys
Expand All @@ -36,14 +58,17 @@ - (UIImageView *)topEmotionImageView {

#pragma mark - Life cycle

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self startPullDownRefreshing];
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = NSLocalizedStringFromTable(@"Expression", @"MessageDisplayKitString", @"");

self.tableView.tableHeaderView = self.topEmotionImageView;

[self loadDataSource];
}

- (void)didReceiveMemoryWarning {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ - (void)callBeginLoadMoreRefreshing {
- (void)endLoadMoreRefresing {
self.loadMoreRefreshing = NO;
self.refreshState = XHRefreshStateNormal;
UIEdgeInsets contentInset = self.scrollView.contentInset;
contentInset.bottom -= CGRectGetHeight(self.loadMoreView.bounds);
self.scrollView.contentInset = contentInset;
[self.loadMoreView endLoading];
}

Expand Down

0 comments on commit a0675ef

Please sign in to comment.