Skip to content

Commit d4c32b3

Browse files
committed
实战使用
1 parent fdea6c5 commit d4c32b3

5 files changed

Lines changed: 22 additions & 32 deletions

File tree

KtTableView/KtTableView/KTMainViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
#import "KtTableViewController.h"
10+
#import "KtRefreshTableViewController.h"
1111

12-
@interface KTMainViewController : KtTableViewController
12+
@interface KTMainViewController : KtRefreshTableViewController
1313

1414
@end
1515

KtTableView/KtTableView/KTMainViewController.m

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
#import "MJRefresh.h"
1818

19-
@interface KTMainViewController ()
19+
@interface KTMainViewController ()<KtBaseListModelProtocol>
2020

21-
@property (strong, nonatomic) KtMainTableModel *model;
21+
//@property (strong, nonatomic) KtMainTableModel *model;
2222

2323
@end
2424

@@ -27,19 +27,12 @@ @implementation KTMainViewController
2727
- (void)viewDidLoad {
2828
[super viewDidLoad];
2929
[self createModel];
30-
31-
self.tableView.isNeedPullUpToRefreshAction = YES;
32-
self.tableView.isNeedPullDownToRefreshAction = YES;
3330
// Do any additional setup after loading the view, typically from a nib.
3431
}
3532

3633
- (void)createModel {
37-
self.model = [[KtMainTableModel alloc] initWithAddress:@"/mooclist.php"];
38-
__weak typeof(self) wSelf = self;
39-
[self.model setCompletionBlock:^(KtBaseModel *model){
40-
__strong typeof(self) sSelf = wSelf;
41-
[sSelf requestBooksSuccess];
42-
}];
34+
self.listModel = [[KtMainTableModel alloc] initWithAddress:@"/mooclist.php"];
35+
self.listModel.delegate = self;
4336
}
4437

4538
- (void)createDataSource {
@@ -51,27 +44,23 @@ - (void)didReceiveMemoryWarning {
5144
// Dispose of any resources that can be recreated.
5245
}
5346

54-
- (void)pullUpToRefreshAction {
55-
[self getFirstPage];
56-
}
57-
58-
- (void)pullDownToRefreshAction {
59-
[self getFirstPage];
60-
}
61-
62-
- (void)getFirstPage {
63-
self.model.params = @{@"nextPage": @0};
64-
[self.model loadWithShortConnection];
47+
- (void)refreshRequestDidSuccess {
48+
[super refreshRequestDidSuccess];
49+
for (KtMainTableBookItem *book in ((KtMainTableModel *)self.listModel).tableViewItem.books) {
50+
KtTableViewBaseItem *item = [[KtTableViewBaseItem alloc] init];
51+
item.itemTitle = book.bookTitle;
52+
[self.dataSource appendItem:item];
53+
}
6554
}
6655

67-
- (void)requestBooksSuccess {
68-
for (KtMainTableBookItem *book in self.model.tableViewItem.books) {
56+
- (void)loadRequestDidSuccess {
57+
[super loadRequestDidSuccess];
58+
for (KtMainTableBookItem *book in ((KtMainTableModel *)self.listModel).tableViewItem.books) {
6959
KtTableViewBaseItem *item = [[KtTableViewBaseItem alloc] init];
7060
item.itemTitle = book.bookTitle;
7161
[self.dataSource appendItem:item];
7262
}
73-
[self.tableView reloadData];
74-
[self.tableView stopRefreshingAnimation];
63+
7564
}
7665

7766
@end

KtTableView/KtTableView/KtMainTableItem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Copyright © 2016年 zxy. All rights reserved.
77
//
88

9-
#import "KtBaseItem.h"
9+
#import "KtBaseListItem.h"
1010

11-
@interface KtMainTableItem : KtBaseItem
11+
@interface KtMainTableItem : KtBaseListItem
1212

1313
@property (strong, nonatomic) NSMutableArray *books; // 存放了每个 cell 的标题
1414

KtTableView/KtTableView/KtMainTableModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// Copyright © 2016年 zxy. All rights reserved.
77
//
88

9-
#import "KtBaseModel.h"
9+
#import "KtBaseListModel.h"
1010
#import "KtMainTableItem.h"
1111

12-
@interface KtMainTableModel : KtBaseModel
12+
@interface KtMainTableModel : KtBaseListModel
1313

1414
@property (nonatomic, strong) KtMainTableItem *tableViewItem;
1515

KtTableView/KtTableView/KtMainTableModel.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@implementation KtMainTableModel
1313

1414
- (void)handleParsedData:(KtBaseItem *)parsedData {
15+
[super handleParsedData:parsedData];
1516
if ([parsedData isKindOfClass:[KtMainTableItem class]]) {
1617
self.tableViewItem = (KtMainTableItem *)parsedData;
1718
}

0 commit comments

Comments
 (0)