Skip to content

Commit f76d37b

Browse files
committed
Created table view delegate arbiter so that collapsable table may intercept some events.
1 parent b8273b4 commit f76d37b

6 files changed

Lines changed: 364 additions & 10 deletions

File tree

STACollapsableTable.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
9376D26B1C64AD8900FC2782 /* STACollapsableTableModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9376D26A1C64AD8900FC2782 /* STACollapsableTableModel.m */; };
2020
9376D2761C65E80000FC2782 /* STATableModelSpecifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 9376D2751C65E7FF00FC2782 /* STATableModelSpecifier.m */; };
2121
9376D2791C67C5B200FC2782 /* STACellModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 9376D2781C67C5B200FC2782 /* STACellModel.m */; };
22+
9376D27C1C6879C700FC2782 /* STATableViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9376D27B1C6879C700FC2782 /* STATableViewDelegate.m */; };
2223
/* End PBXBuildFile section */
2324

2425
/* Begin PBXContainerItemProxy section */
@@ -52,6 +53,8 @@
5253
9376D2751C65E7FF00FC2782 /* STATableModelSpecifier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STATableModelSpecifier.m; sourceTree = "<group>"; };
5354
9376D2771C67C5B200FC2782 /* STACellModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STACellModel.h; sourceTree = "<group>"; };
5455
9376D2781C67C5B200FC2782 /* STACellModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STACellModel.m; sourceTree = "<group>"; };
56+
9376D27A1C6879C700FC2782 /* STATableViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STATableViewDelegate.h; sourceTree = "<group>"; };
57+
9376D27B1C6879C700FC2782 /* STATableViewDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STATableViewDelegate.m; sourceTree = "<group>"; };
5558
B11300C9268E6B1CC3A20906 /* Pods-STACollapsableTable.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-STACollapsableTable.release.xcconfig"; path = "Pods/Target Support Files/Pods-STACollapsableTable/Pods-STACollapsableTable.release.xcconfig"; sourceTree = "<group>"; };
5659
E9F18E2C01F0AB9AB7B6ACDC /* Pods-STACollapsableTable.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-STACollapsableTable.debug.xcconfig"; path = "Pods/Target Support Files/Pods-STACollapsableTable/Pods-STACollapsableTable.debug.xcconfig"; sourceTree = "<group>"; };
5760
/* End PBXFileReference section */
@@ -130,6 +133,8 @@
130133
9376D2751C65E7FF00FC2782 /* STATableModelSpecifier.m */,
131134
9376D2771C67C5B200FC2782 /* STACellModel.h */,
132135
9376D2781C67C5B200FC2782 /* STACellModel.m */,
136+
9376D27A1C6879C700FC2782 /* STATableViewDelegate.h */,
137+
9376D27B1C6879C700FC2782 /* STATableViewDelegate.m */,
133138
);
134139
path = STACollapsableTable;
135140
sourceTree = "<group>";
@@ -304,6 +309,7 @@
304309
buildActionMask = 2147483647;
305310
files = (
306311
9376D2791C67C5B200FC2782 /* STACellModel.m in Sources */,
312+
9376D27C1C6879C700FC2782 /* STATableViewDelegate.m in Sources */,
307313
9376D26B1C64AD8900FC2782 /* STACollapsableTableModel.m in Sources */,
308314
9376D25C1C649FB500FC2782 /* main.m in Sources */,
309315
9376D25D1C649FB500FC2782 /* SampleTableViewController.m in Sources */,

STACollapsableTable/STACollapsableTableModel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@
3232
@interface STACollapsableTableModel : NSObject
3333

3434
@property (nonatomic, weak) id<STACollapsableTableModelDelegate> delegate;
35-
@property (nonatomic, readonly) id dataSource;
35+
@property (nonatomic, readonly) id tableViewDataSource;
36+
@property (nonatomic, readonly) id tableViewDelegate;
3637

3738
- (instancetype)initWithContentsArray:(NSArray *)contentsArray
3839
delegate:(id<STACollapsableTableModelDelegate>)delegate;
3940

41+
- (STACellModel *)cellModelAtIndexPath:(NSIndexPath *)indexPath;
42+
4043
@end

STACollapsableTable/STACollapsableTableModel.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
#import <Nimbus/NICellCatalog.h>
1212
#import "STATableModelSpecifier.h"
1313
#import "STACellModel.h"
14+
#import "STATableViewDelegate.h"
1415

1516
typedef void (^ObjectEnumeratorBlock)(id object);
1617

1718
@interface STACollapsableTableModel () <NITableViewModelDelegate>
1819

1920
@property (nonatomic, strong) NSArray *dataArray;
2021
@property (nonatomic, strong) NIMutableTableViewModel *tableModel;
22+
@property (nonatomic, strong) STATableViewDelegate *tableViewDelegateArbiter;
2123

2224
@end
2325

@@ -32,9 +34,10 @@ @implementation STACollapsableTableModel
3234
//}
3335

3436
- (instancetype)initWithContentsArray:(NSArray *)contentsArray
35-
delegate:(id<STACollapsableTableModelDelegate>)delegate
37+
delegate:(id<STACollapsableTableModelDelegate, UITableViewDelegate>)delegate
3638
{
3739
if (self = [super init]) {
40+
_tableViewDelegateArbiter = [[STATableViewDelegate alloc] initWithInternalDelegate:self externalDelegate:delegate];
3841
[self parseContents:contentsArray];
3942
_delegate = delegate;
4043
}
@@ -43,10 +46,20 @@ - (instancetype)initWithContentsArray:(NSArray *)contentsArray
4346

4447
#pragma mark - Getters
4548

46-
- (id)dataSource {
49+
- (id)tableViewDataSource {
4750
return self.tableModel;
4851
}
4952

53+
- (id)tableViewDelegate {
54+
return self.tableViewDelegateArbiter;
55+
}
56+
57+
#pragma mark - Public Methods
58+
59+
- (STACellModel *)cellModelAtIndexPath:(NSIndexPath *)indexPath {
60+
return [self.tableModel objectAtIndexPath:indexPath];
61+
}
62+
5063
#pragma mark - Private Methods
5164

5265
- (void)parseContents:(NSArray *)contentsArray {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// STATableViewDelegate.h
3+
// STACollapsableTable
4+
//
5+
// Created by Aaron Jubbal on 2/7/16.
6+
// Copyright © 2016 Aaron Jubbal. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <UIKit/UIKit.h>
11+
12+
@interface STATableViewDelegate : NSObject
13+
14+
- (instancetype)initWithInternalDelegate:(id)internalDelegate
15+
externalDelegate:(id<UITableViewDelegate>)externalDelegate;
16+
17+
@end

0 commit comments

Comments
 (0)