14
14
@implementation SomoDataSourceProvider
15
15
{
16
16
NSString * _reuseIdentifier;
17
+ SomoTableViewCellBlock _tableViewCellBlock;
18
+ SomoCollectionViewCellBlock _collectionViewCellBlock;
17
19
}
18
20
19
21
- (instancetype )initWithCellReuseIdentifier : (NSString *)reuseIdentifier {
@@ -28,13 +30,32 @@ + (instancetype)dataSourceProviderWithCellReuseIdentifier:(NSString *)reuseIdent
28
30
return [[[self class ] alloc ] initWithCellReuseIdentifier: reuseIdentifier];
29
31
}
30
32
33
+ - (instancetype )initWithTableViewCellBlock : (SomoTableViewCellBlock)block {
34
+ if (self = [super init ]) {
35
+ _tableViewCellBlock = block;
36
+ _numberOfRowsInSection = 30 ;
37
+ }
38
+ return self;
39
+ }
40
+
41
+ - (instancetype )initWithCollectionViewCellBlock : (SomoCollectionViewCellBlock)block {
42
+ if (self = [super init ]) {
43
+ _collectionViewCellBlock = block;
44
+ _numberOfRowsInSection = 30 ;
45
+ }
46
+ return self;
47
+ }
48
+
31
49
- (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
32
50
return self.numberOfRowsInSection ;
33
51
}
34
52
35
53
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
36
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: _reuseIdentifier forIndexPath: indexPath];
37
- return cell;
54
+ if (_reuseIdentifier) {
55
+ return [tableView dequeueReusableCellWithIdentifier: _reuseIdentifier forIndexPath: indexPath];
56
+ }else {
57
+ return _tableViewCellBlock (tableView,indexPath);
58
+ }
38
59
}
39
60
40
61
- (void )tableView : (UITableView *)tableView willDisplayCell : (UITableViewCell *)cell forRowAtIndexPath : (NSIndexPath *)indexPath {
@@ -48,8 +69,11 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
48
69
}
49
70
50
71
- (__kindof UICollectionViewCell *)collectionView : (UICollectionView *)collectionView cellForItemAtIndexPath : (NSIndexPath *)indexPath {
51
- UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier: _reuseIdentifier forIndexPath: indexPath];
52
- return cell;
72
+ if (_reuseIdentifier) {
73
+ return [collectionView dequeueReusableCellWithReuseIdentifier: _reuseIdentifier forIndexPath: indexPath];
74
+ }else {
75
+ return _collectionViewCellBlock (collectionView, indexPath);
76
+ }
53
77
}
54
78
55
79
- (void )collectionView : (UICollectionView *)collectionView willDisplayCell : (UICollectionViewCell *)cell forItemAtIndexPath : (NSIndexPath *)indexPath {
0 commit comments