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
0 commit comments