Skip to content

Commit b254225

Browse files
committed
子类model与item的使用
1 parent 77c6392 commit b254225

5 files changed

Lines changed: 114 additions & 0 deletions

File tree

KtTableView/KtTableView.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
E19B41191CC21555008A3E7F /* KtTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E19B41181CC21555008A3E7F /* KtTableViewController.m */; };
2828
E1DCC9EF1CE5A61A00CDC83D /* KtBaseModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E1DCC9EE1CE5A61A00CDC83D /* KtBaseModel.m */; };
2929
E1DCC9F21CE5A6A000CDC83D /* KtBaseServerAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = E1DCC9F11CE5A6A000CDC83D /* KtBaseServerAPI.m */; };
30+
E1DCC9F51CE5A76D00CDC83D /* KtMainTableModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E1DCC9F41CE5A76D00CDC83D /* KtMainTableModel.m */; };
3031
E1DCC9F81CE5A81000CDC83D /* KtBaseItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E1DCC9F71CE5A81000CDC83D /* KtBaseItem.m */; };
32+
E1DCC9FB1CE5A99C00CDC83D /* KtMainTableItem.m in Sources */ = {isa = PBXBuildFile; fileRef = E1DCC9FA1CE5A99C00CDC83D /* KtMainTableItem.m */; };
3133
E1EE5C9D1CBE811C0095688B /* KtBaseTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = E1EE5C9C1CBE811C0095688B /* KtBaseTableView.m */; };
3234
/* End PBXBuildFile section */
3335

@@ -90,8 +92,12 @@
9092
E1DCC9EE1CE5A61A00CDC83D /* KtBaseModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtBaseModel.m; sourceTree = "<group>"; };
9193
E1DCC9F01CE5A6A000CDC83D /* KtBaseServerAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtBaseServerAPI.h; sourceTree = "<group>"; };
9294
E1DCC9F11CE5A6A000CDC83D /* KtBaseServerAPI.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtBaseServerAPI.m; sourceTree = "<group>"; };
95+
E1DCC9F31CE5A76D00CDC83D /* KtMainTableModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtMainTableModel.h; sourceTree = "<group>"; };
96+
E1DCC9F41CE5A76D00CDC83D /* KtMainTableModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtMainTableModel.m; sourceTree = "<group>"; };
9397
E1DCC9F61CE5A81000CDC83D /* KtBaseItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtBaseItem.h; sourceTree = "<group>"; };
9498
E1DCC9F71CE5A81000CDC83D /* KtBaseItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtBaseItem.m; sourceTree = "<group>"; };
99+
E1DCC9F91CE5A99C00CDC83D /* KtMainTableItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtMainTableItem.h; sourceTree = "<group>"; };
100+
E1DCC9FA1CE5A99C00CDC83D /* KtMainTableItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtMainTableItem.m; sourceTree = "<group>"; };
95101
E1EE5C9B1CBE811C0095688B /* KtBaseTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KtBaseTableView.h; sourceTree = "<group>"; };
96102
E1EE5C9C1CBE811C0095688B /* KtBaseTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KtBaseTableView.m; sourceTree = "<group>"; };
97103
/* End PBXFileReference section */
@@ -193,6 +199,10 @@
193199
E1621E041CBDF267003D9438 /* AppDelegate.m */,
194200
E1621E061CBDF267003D9438 /* KTMainViewController.h */,
195201
E1621E071CBDF267003D9438 /* KTMainViewController.m */,
202+
E1DCC9F31CE5A76D00CDC83D /* KtMainTableModel.h */,
203+
E1DCC9F41CE5A76D00CDC83D /* KtMainTableModel.m */,
204+
E1DCC9F91CE5A99C00CDC83D /* KtMainTableItem.h */,
205+
E1DCC9FA1CE5A99C00CDC83D /* KtMainTableItem.m */,
196206
E108B2B21CBE1C9100191E0B /* KtMainTableViewDataSource.h */,
197207
E108B2B31CBE1C9100191E0B /* KtMainTableViewDataSource.m */,
198208
E108B2A51CBE0A2600191E0B /* KtMainTableViewCell.h */,
@@ -445,9 +455,11 @@
445455
E1DCC9EF1CE5A61A00CDC83D /* KtBaseModel.m in Sources */,
446456
E1DCC9F21CE5A6A000CDC83D /* KtBaseServerAPI.m in Sources */,
447457
E1621E081CBDF267003D9438 /* KTMainViewController.m in Sources */,
458+
E1DCC9FB1CE5A99C00CDC83D /* KtMainTableItem.m in Sources */,
448459
E1EE5C9D1CBE811C0095688B /* KtBaseTableView.m in Sources */,
449460
E1621E051CBDF267003D9438 /* AppDelegate.m in Sources */,
450461
E108B2AE1CBE15D800191E0B /* KtTableViewSectionObject.m in Sources */,
462+
E1DCC9F51CE5A76D00CDC83D /* KtMainTableModel.m in Sources */,
451463
E1621E021CBDF265003D9438 /* main.m in Sources */,
452464
E108B2A71CBE0A2600191E0B /* KtMainTableViewCell.m in Sources */,
453465
);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// KtMainTableItem.h
3+
// KtTableView
4+
//
5+
// Created by baidu on 16/5/13.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import "KtBaseItem.h"
10+
11+
@interface KtMainTableItem : KtBaseItem
12+
13+
@property (strong, nonatomic) NSMutableArray *books; // 存放了每个 cell 的标题
14+
15+
@end
16+
17+
@interface KtMainTableBookItem : KtBaseItem
18+
19+
@property (copy, nonatomic) NSString *bookTitle;
20+
@property (copy, nonatomic) NSString *url;
21+
@property (copy, nonatomic) NSString *imageUrl;
22+
23+
@end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// KtMainTableItem.m
3+
// KtTableView
4+
//
5+
// Created by baidu on 16/5/13.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import "KtMainTableItem.h"
10+
11+
@implementation KtMainTableItem
12+
13+
- (id)init {
14+
self = [super init];
15+
if (self) {
16+
[self addMappingRuleProperty:@"books" pathInJson:@"data"];
17+
[self addMappingRuleArrayProperty:@"books" class:[KtMainTableBookItem class]];
18+
}
19+
return self;
20+
}
21+
22+
@end
23+
24+
@implementation KtMainTableBookItem
25+
26+
- (id)init {
27+
self = [super init];
28+
if (self) {
29+
[self addMappingRuleProperty:@"bookTitle" pathInJson:@"title"];
30+
[self addMappingRuleProperty:@"url" pathInJson:@"url"];
31+
[self addMappingRuleProperty:@"imageUrl" pathInJson:@"imageUrl"];
32+
}
33+
return self;
34+
}
35+
36+
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// KtMainTableModel.h
3+
// KtTableView
4+
//
5+
// Created by baidu on 16/5/13.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import "KtBaseModel.h"
10+
#import "KtMainTableItem.h"
11+
12+
@interface KtMainTableModel : KtBaseModel
13+
14+
@property (nonatomic, strong) KtMainTableItem *tableViewItem;
15+
16+
@end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// KtMainTableModel.m
3+
// KtTableView
4+
//
5+
// Created by baidu on 16/5/13.
6+
// Copyright © 2016年 zxy. All rights reserved.
7+
//
8+
9+
#import "KtMainTableModel.h"
10+
#import "KtMainTableItem.h"
11+
12+
@implementation KtMainTableModel
13+
14+
- (void)handleParsedData:(KtBaseItem *)parsedData {
15+
if ([parsedData isKindOfClass:[KtMainTableItem class]]) {
16+
self.tableViewItem = (KtMainTableItem *)parsedData;
17+
}
18+
}
19+
20+
- (void)loadWithShortConnection {
21+
if (!self.parseDataClassType) {
22+
self.parseDataClassType = [KtMainTableItem class];
23+
}
24+
[super loadWithShortConnection];
25+
}
26+
27+
@end

0 commit comments

Comments
 (0)