Skip to content

Commit

Permalink
配置并测试朋友圈页面的数据源,加入上拉刷新功能
Browse files Browse the repository at this point in the history
  • Loading branch information
siegrainwong committed Apr 23, 2016
1 parent 0fd2687 commit 8a674a3
Show file tree
Hide file tree
Showing 35 changed files with 476 additions and 123 deletions.
118 changes: 112 additions & 6 deletions WeChat.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion WeChat/Chat/Controller/ChatroomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ - (void)buildEditorView
/*
若要在修改约束的同时进行动画的话,需要调用其父视图的layoutIfNeeded方法,并在动画中再调用一次
*/

[weakSelf.editorView mas_updateConstraints:^(MASConstraintMaker* make) {
make.bottom.offset(-keyboardSize.height);
}];
Expand Down
13 changes: 0 additions & 13 deletions WeChat/Found/Controller/CoverHeaderViewController.h

This file was deleted.

52 changes: 0 additions & 52 deletions WeChat/Found/Controller/CoverHeaderViewController.m

This file was deleted.

3 changes: 3 additions & 0 deletions WeChat/Found/Controller/DiscoverViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ - (CGFloat)tableView:(UITableView*)tableView
- (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
if (indexPath.section != 0)
return;

MomentsTableViewController* destinationVC =
[[MomentsTableViewController alloc] init];
destinationVC.hidesBottomBarWhenPushed = true;
Expand Down
137 changes: 97 additions & 40 deletions WeChat/Found/Controller/MomentsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,146 @@
//

#import "CoverHeaderView.h"
#import "MJRefresh/MJRefresh/Custom/Footer/Auto/MJRefreshAutoNormalFooter.h"
#import "Masonry/Masonry/Masonry.h"
#import "Moment.h"
#import "MomentsDataSource.h"
#import "MomentsTableViewController.h"
#import "SpinningLoadingView.h"

@interface
MomentsTableViewController ()
@property (strong, nonatomic) CoverHeaderView* coverView;
@property (assign, nonatomic) float contentInsetY;

@property (strong, nonatomic) MomentsDataSource* datasource;
@property (strong, nonatomic) NSMutableArray<Moment*>* momentsArray;
@end

@implementation MomentsTableViewController
- (NSMutableArray<Moment*>*)momentsArray
{
if (_momentsArray == nil) {
_momentsArray = [NSMutableArray array];
}
return _momentsArray;
}
- (MomentsDataSource*)datasource
{
static MomentsDataSource* datasource = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
datasource = [[MomentsDataSource alloc] init];
});

return datasource;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.contentInsetY = -150;
[super viewDidLoad];
self.contentInsetY = -150;

[self buildTableview];
[self bindConstraints];
[self buildTableview];
[self bindConstraints];
[self loadData:true];
}
- (void)buildTableview
{
self.coverView = [CoverHeaderView
coverHeaderWithCover:[UIImage imageNamed:@"cover"]
avatar:[UIImage imageNamed:@"siegrain_avatar"]
name:@"Siegrain Wong"];
self.tableView.contentInset = UIEdgeInsetsMake(self.contentInsetY, 0, 0, 0);
self.tableView.tableHeaderView = self.coverView;
self.coverView = [CoverHeaderView
coverHeaderWithCover:[UIImage imageNamed:@"cover"]
avatar:[UIImage imageNamed:@"siegrain_avatar"]
name:@"Siegrain Wong"];
self.tableView.contentInset = UIEdgeInsetsMake(self.contentInsetY, 0, 0, 0);
self.tableView.tableHeaderView = self.coverView;

SpinningLoadingView* loadingView =
[SpinningLoadingView headerWithRefreshingBlock:^{
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
[self loadData:true];
[self.tableView.mj_header endRefreshing];
});
}];
loadingView.ignoredScrollViewContentInsetTop = self.contentInsetY;
self.tableView.mj_header = loadingView;

SpinningLoadingView* loadingView =
[SpinningLoadingView headerWithRefreshingBlock:^{
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
// self.tableView.contentOffset = CGPointMake(0, -124);
// [UIView animateWithDuration:0.5
// animations:^{
// self.tableView.contentOffset =
// CGPointMake(0, 86);
// }];
[self.tableView.mj_header endRefreshing];
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(),
^{
[self loadData:false];
[self.tableView.mj_footer endRefreshing];
});
}];
loadingView.ignoredScrollViewContentInsetTop = self.contentInsetY;
self.tableView.mj_header = loadingView;

// tableview.header默认是在tableview.tableHeaerView后面的
[self.tableView bringSubviewToFront:self.tableView.mj_header];
}
- (void)bindConstraints
{
[self.coverView mas_makeConstraints:^(MASConstraintMaker* make) {
make.right.left.top.offset(0);
make.height.width.equalTo(self.tableView.mas_width);
}];
[self.coverView mas_makeConstraints:^(MASConstraintMaker* make) {
make.right.left.top.offset(0);
make.width.equalTo(self.tableView.mas_width);
make.height.equalTo(self.tableView.mas_width).offset(30);
}];
}

- (void)loadData:(BOOL)isInitial
{
if (isInitial) [self.momentsArray removeAllObjects];

NSArray* datas = [self.datasource moments];
[self.momentsArray addObjectsFromArray:datas];

if (isInitial)
[self.tableView reloadData];
else {
NSMutableArray* indexPaths = [NSMutableArray array];
for (NSUInteger i = 0; i < datas.count; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}

[UIView setAnimationsEnabled:false];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
[UIView setAnimationsEnabled:true];
}

/*
tableview.header默认是在tableview.tableHeaerView后面的
而且每次更新表格后都会重置这个顺序,所以每次刷新都要执行一次这个方法
*/
[self.tableView bringSubviewToFront:self.tableView.mj_header];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
[super didReceiveMemoryWarning];
}

#pragma mark - tableview
- (CGFloat)tableView:(UITableView*)tableView
heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
return 50;
return 50;
}
- (NSInteger)tableView:(UITableView*)tableView
numberOfRowsInSection:(NSInteger)section
numberOfRowsInSection:(NSInteger)section
{
return 50;
return self.momentsArray.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell* cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"ss"];
cell.textLabel.text = @"尼玛。。。。";
return cell;
UITableViewCell* cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"ss"];
cell.textLabel.text = self.momentsArray[indexPath.row].content;
return cell;
}
#pragma mark - scrollview
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
NSLog(@"%f", scrollView.contentOffset.y);
// NSLog(@"%f", scrollView.contentOffset.y);
}
@end
20 changes: 20 additions & 0 deletions WeChat/Found/Model/Moment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Moment.h
// WeChat
//
// Created by Siegrain on 16/4/23.
// Copyright © 2016年 siegrain. weChat. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface Moment : NSObject
@property (copy, nonatomic) NSString* content;
@property (copy, nonatomic) NSString* name;
@property (strong, nonatomic) UIImage* avatar;

@property (copy, nonatomic) NSArray* pictures;
@property (copy, nonatomic) NSArray* comments;

+ (instancetype)momentWithContent:(NSString*)content name:(NSString*)name pictures:(NSArray*)pictures comments:(NSArray*)comments;
@end
22 changes: 22 additions & 0 deletions WeChat/Found/Model/Moment.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Moment.m
// WeChat
//
// Created by Siegrain on 16/4/23.
// Copyright © 2016年 siegrain. weChat. All rights reserved.
//

#import "Moment.h"

@implementation Moment
+ (instancetype)momentWithContent:(NSString*)content name:(NSString*)name pictures:(NSArray*)pictures comments:(NSArray*)comments
{
Moment* model = [[Moment alloc] init];
model.content = content;
model.name = name;
model.pictures = pictures;
model.comments = comments;

return model;
}
@end
14 changes: 14 additions & 0 deletions WeChat/Found/MomentsDataSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// MomentsDataSource.h
// WeChat
//
// Created by Siegrain on 16/4/23.
// Copyright © 2016年 siegrain. weChat. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface MomentsDataSource : NSObject
- (NSString*)randomName;
- (NSArray*)moments;
@end
Loading

0 comments on commit 8a674a3

Please sign in to comment.