Skip to content

Commit

Permalink
fix:reload tableview
Browse files Browse the repository at this point in the history
  • Loading branch information
knightsj committed Apr 23, 2017
1 parent b4529a6 commit 545741e
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 29 deletions.
2 changes: 1 addition & 1 deletion SJStaticTableView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Pod::Spec.new do |s|

s.name = "SJStaticTableView"
s.version = "1.1.2"
s.version = "1.2.0"
s.summary = "SJStaticTableView can be used to establish ViewControllers which contain static tableview such as setting page and userinfo page."
s.homepage = "https://github.com/knightsj/SJStaticTableView"
s.license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions SJStaticTableViewComponent/Factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
//定制cell页 - 同组
+ (NSArray *)customCellsOneSectionPageData;

//表情页
+ (NSArray *)emoticonPage;

@end
35 changes: 35 additions & 0 deletions SJStaticTableViewComponent/Factory.m
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,39 @@ + (NSArray *)customCellsOneSectionPageData
return @[section1];
}

+ (NSArray *)emoticonPage
{
// ========== section 0
SJStaticTableviewCellViewModel *vm0 = [[SJStaticTableviewCellViewModel alloc] init];
vm0.leftImage = [UIImage imageNamed:@"emoji_1"];
vm0.leftTitle = @"眨眼";

SJStaticTableviewCellViewModel *vm1 = [[SJStaticTableviewCellViewModel alloc] init];
vm1.leftImage = [UIImage imageNamed:@"emoji_2"];
vm1.leftTitle = @"伸舌";

SJStaticTableviewCellViewModel *vm2 = [[SJStaticTableviewCellViewModel alloc] init];
vm2.leftImage = [UIImage imageNamed:@"emoji_3"];
vm2.leftTitle = @"哭笑";

SJStaticTableviewCellViewModel *vm3 = [[SJStaticTableviewCellViewModel alloc] init];
vm3.leftImage = [UIImage imageNamed:@"emoji_4"];
vm3.leftTitle = @"大笑";

SJStaticTableviewCellViewModel *vm4 = [[SJStaticTableviewCellViewModel alloc] init];
vm4.leftImage = [UIImage imageNamed:@"emoji_5"];
vm4.leftTitle = @"魔鬼";

SJStaticTableviewCellViewModel *vm5 = [[SJStaticTableviewCellViewModel alloc] init];
vm5.leftImage = [UIImage imageNamed:@"emoji_6"];
vm5.leftTitle = @"大哭";


SJStaticTableviewSectionViewModel *section0 = [[SJStaticTableviewSectionViewModel alloc] initWithCellViewModelsArray: @[vm0,vm1,vm2,vm3,vm4,vm5]];



return @[section0];
}

@end
16 changes: 14 additions & 2 deletions SJStaticTableViewComponent/SJStaticTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@
- (void)createDataSource;
@end

typedef enum : NSUInteger {

SJDefaultDataTypeExist, //可以生成默认数据源(1. 完全不依赖网络请求,有现成的数据 2. 先生成默认数据源,然后通过网络请求来刷新表格)
SJDefaultDataTypeNone, //无法生成默认数据源,完全依赖网络请求,拿到数据后,生成表格

}SJDefaultDataType;


@interface SJStaticTableViewController : UIViewController<SJStaticTableViewControllerDelegate,SJStaticTableViewDelegate>

@property (nonatomic, strong) SJStaticTableView *tableView;
@property (nonatomic, strong) SJStaticTableViewDataSource *dataSource;
@property (nonatomic, readwrite, strong) SJStaticTableView *tableView;
@property (nonatomic, readwrite, strong) SJStaticTableViewDataSource *dataSource;
@property (nonatomic, readonly, assign) SJDefaultDataType defualtDataType;

- (instancetype)initWithDefaultDataType:(SJDefaultDataType)defualtDataType;
- (void)configureTableView;

@end
44 changes: 38 additions & 6 deletions SJStaticTableViewComponent/SJStaticTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,46 @@

@interface SJStaticTableViewController()

@property (nonatomic, readwrite, assign) SJDefaultDataType defualtDataType;

@end


@implementation SJStaticTableViewController

#pragma mark- init

- (instancetype)initWithDefaultDataType:(SJDefaultDataType)defualtDataType
{
self = [super init];
if (self) {
self.defualtDataType = defualtDataType;
}
return self;
}

- (instancetype)init
{
self = [self initWithDefaultDataType:SJDefaultDataTypeExist];
return self;
}

#pragma mark- life circle
- (void)viewDidLoad {

[super viewDidLoad];
[self configNav];
[self createDataSource];
[self createTableView];
[self configureNav];

//在能够提供给tableivew全部,或者部分数据源的情况下,可以先构造出tableview;
//否则,需要在网络请求结束后,手动调用configureTableView方法
if (self.defualtDataType == SJDefaultDataTypeExist) {
[self configureTableView];
}

}

- (void)configNav
#pragma mark- configure subviews
- (void)configureNav
{
self.automaticallyAdjustsScrollViewInsets = NO;
//修改导航条背景色
Expand All @@ -38,12 +63,19 @@ - (void)configNav
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}

- (void)createDataSource
- (void)configureTableView
{
//子类去实现
[self createDataSource];
[self createTableView];
}


- (void)createDataSource
{
//交给子类实现

}

- (void)createTableView {

if (!self.tableView) {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

typedef enum : NSUInteger {

SJDefaultDataTypeExist, //可以生成默认数据源(1. 完全不依赖网络请求,有现成的数据 2. 先生成默认数据源之,然后通过网络请求来刷新
SJDefaultDataTypeNone, //无法生成默认数据源,完全依赖网络请求
SJDefaultDataTypeExist, //可以生成默认数据源(1. 完全不依赖网络请求,有现成的数据 2. 先生成默认数据源,然后通过网络请求来刷新表格
SJDefaultDataTypeNone, //无法生成默认数据源,完全依赖网络请求,拿到数据后,生成表格

}SJDefaultDataType;

Expand All @@ -30,7 +30,6 @@ typedef enum : NSUInteger {
@property (nonatomic, readwrite, strong) SJStaticTableView *tableView;
@property (nonatomic, readwrite, strong) SJStaticTableViewDataSource *dataSource;
@property (nonatomic, readonly, assign) SJDefaultDataType defualtDataType;
@property (nonatomic, readwrite, strong) NSArray *modelsArray;

- (instancetype)initWithDefaultDataType:(SJDefaultDataType)defualtDataType;
- (void)configureTableView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ - (void)configureTableView

- (void)createDataSource
{
//交给子类去做
//交给子类实现

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ - (void)viewDidLoad {

[super viewDidLoad];
self.navigationItem.title = @"定制cell页面 - 同组";
self.modelsArray = [Factory customCellsOneSectionPageData];
}


- (void)createDataSource
{
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:self.modelsArray configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:[Factory customCellsOneSectionPageData] configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {

switch (viewModel.staticCellType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ - (void)viewDidLoad {

[super viewDidLoad];
self.navigationItem.title = @"定制cell页面 - 分组";
self.modelsArray = [Factory customCellsPageData];
}


- (void)createDataSource
{
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:self.modelsArray configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:[Factory customCellsPageData] configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {

switch (viewModel.staticCellType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ - (void)viewDidLoad {

[super viewDidLoad];
self.navigationItem.title = @"发现";
self.modelsArray = [Factory momentsPageData];
[self networkRequest];
}

Expand Down Expand Up @@ -47,14 +46,14 @@ - (void)networkRequest
viewModel.indicatorLeftTitle = responseDict[@"game_info"];

//刷新tableview
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
}
});
}

- (void)createDataSource
{
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:self.modelsArray configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:[Factory momentsPageData] configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {

switch (viewModel.staticCellType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@interface SJEmoticonViewController ()

@property (nonatomic, readwrite, strong) NSArray *modelsArray;

@end

@implementation SJEmoticonViewController
Expand All @@ -21,19 +23,19 @@ - (void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.title = @"表情";
[self networdRequest];
[self networkRequest];
}


- (void)networdRequest
- (void)networkRequest
{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];

//模拟网络请求
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[MBProgressHUD hideHUDForView:self.view animated:YES];
self.modelsArray = [Factory emoticonPage];
self.modelsArray = [Factory emoticonPage];//网络请求后,将数据保存在self.modelsArray里面
[self configureTableView];

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ @implementation SJInfoViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"个人信息";
self.modelsArray = [Factory infoPageData];
}



- (void)createDataSource
{
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:self.modelsArray configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:[Factory infoPageData] configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {

switch (viewModel.staticCellType)
{
Expand All @@ -40,4 +41,5 @@ - (void)createDataSource
}



@end
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ - (void)viewDidLoad {

[super viewDidLoad];
self.navigationItem.title = @"";
self.modelsArray = [Factory mePageData];
}

- (void)createDataSource
{
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:self.modelsArray configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:[Factory mePageData] configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {

switch (viewModel.staticCellType) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ - (void)viewDidLoad {

[super viewDidLoad];
self.navigationItem.title = @"设置";
self.modelsArray = [Factory settingPageData];
}

- (void)createDataSource
{
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:self.modelsArray configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {
self.dataSource = [[SJStaticTableViewDataSource alloc] initWithViewModelsArray:[Factory settingPageData] configureBlock:^(SJStaticTableViewCell *cell, SJStaticTableviewCellViewModel *viewModel) {

switch (viewModel.staticCellType)
{
Expand Down

0 comments on commit 545741e

Please sign in to comment.