Skip to content

Commit

Permalink
Merge pull request #4 from grigaci/features/tableViewFixes
Browse files Browse the repository at this point in the history
Table view improvements
  • Loading branch information
grigaci committed Aug 17, 2015
2 parents 2678c81 + 50a58d7 commit 51ed040
Show file tree
Hide file tree
Showing 77 changed files with 3,831 additions and 4,017 deletions.
10 changes: 10 additions & 0 deletions BIObjCHelpers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
4304A9B61B70D892009739B3 /* BIDatasourceTableViewTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 4304A9B51B70D892009739B3 /* BIDatasourceTableViewTestCase.m */; };
435533511B81B87F0052A128 /* _BITableView+Internal.m in Sources */ = {isa = PBXBuildFile; fileRef = 435533501B81B87F0052A128 /* _BITableView+Internal.m */; };
435D59C01B622E8A00ECA859 /* BIMockHandlerTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 435D59BF1B622E8A00ECA859 /* BIMockHandlerTableView.m */; };
43BE6C311B56882B001F0A00 /* libBIObjCHelpers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 43BE6C251B56882B001F0A00 /* libBIObjCHelpers.a */; };
43BE6C721B5689CA001F0A00 /* BITableViewBatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 43BE6C421B5689C9001F0A00 /* BITableViewBatch.m */; };
Expand Down Expand Up @@ -78,6 +80,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
4304A9B51B70D892009739B3 /* BIDatasourceTableViewTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BIDatasourceTableViewTestCase.m; sourceTree = "<group>"; };
4355334F1B81B87F0052A128 /* _BITableView+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "_BITableView+Internal.h"; path = "Views/TableView/_BITableView+Internal.h"; sourceTree = "<group>"; };
435533501B81B87F0052A128 /* _BITableView+Internal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "_BITableView+Internal.m"; path = "Views/TableView/_BITableView+Internal.m"; sourceTree = "<group>"; };
435D59BE1B622E8A00ECA859 /* BIMockHandlerTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BIMockHandlerTableView.h; path = BIHandlerTableView/BIMockHandlerTableView.h; sourceTree = "<group>"; };
435D59BF1B622E8A00ECA859 /* BIMockHandlerTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BIMockHandlerTableView.m; path = BIHandlerTableView/BIMockHandlerTableView.m; sourceTree = "<group>"; };
43BE6C251B56882B001F0A00 /* libBIObjCHelpers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBIObjCHelpers.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -581,6 +586,7 @@
43BE6CE51B568ECB001F0A00 /* TableView */ = {
isa = PBXGroup;
children = (
4304A9B51B70D892009739B3 /* BIDatasourceTableViewTestCase.m */,
43BE6CE61B568ECB001F0A00 /* BIDatasourceFeedTableViewTestCase.m */,
43BE6CE71B568ECB001F0A00 /* BIDatasourceFetchedTableViewTestCase.m */,
43BE6CE81B568ECB001F0A00 /* BIMockDatasourceFeedTableView.h */,
Expand Down Expand Up @@ -708,6 +714,8 @@
91E59B861B5840CD0034824F /* BITableView.m */,
43DA59461B6209EF00ECAAC0 /* _BITableViewProxy.h */,
43DA59471B6209EF00ECAAC0 /* _BITableViewProxy.m */,
4355334F1B81B87F0052A128 /* _BITableView+Internal.h */,
435533501B81B87F0052A128 /* _BITableView+Internal.m */,
);
name = TableView;
sourceTree = "<group>";
Expand Down Expand Up @@ -898,6 +906,7 @@
91E59B871B5840CD0034824F /* BITableView.m in Sources */,
43BE6C7D1B5689CA001F0A00 /* BIHandlerTableView.m in Sources */,
43DA59481B6209EF00ECAAC0 /* _BITableViewProxy.m in Sources */,
435533511B81B87F0052A128 /* _BITableView+Internal.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -912,6 +921,7 @@
43BE6CFB1B568ECB001F0A00 /* BIDatasourceFetchedCollectionViewTestCase.m in Sources */,
43BE6CFC1B568ECB001F0A00 /* BIMockDatasourceFetchedCollectionView.m in Sources */,
43BE6D051B568ECB001F0A00 /* BIMockStarter.m in Sources */,
4304A9B61B70D892009739B3 /* BIDatasourceTableViewTestCase.m in Sources */,
43BE6D001B568ECB001F0A00 /* BIHandlerTableViewTestCase.m in Sources */,
43BE6CD01B568B1F001F0A00 /* BITestCaseCoreData.m in Sources */,
914D2CB51B57BB41009A9B4D /* BIBatchFetchingTestCase.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion BIObjCHelpers/Batch/TableView/BITableViewBatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "BITableViewBatch.h"

const NSInteger kDefaultTableViewBatchSize = 10;
const NSInteger kDefaultTableViewBatchSize = 3;

@interface BITableViewBatch ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@property (nonatomic, strong, readonly, nonnull) BITableView *tableView;

+ (nonnull instancetype)datasourceWithBITableView:(nonnull BITableView *)tableView;
+ (nonnull instancetype)datasourceWithTableView:(nonnull UITableView *)tableView NS_UNAVAILABLE;
- (nonnull instancetype)initWithTableView:(nonnull UITableView *)tableView NS_UNAVAILABLE;

- (nonnull BITableViewBatch *)createNextBatch;
- (void)fetchBatch:(nonnull BITableViewBatch *)batch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ @implementation BIDatasourceFeedTableView
@synthesize cellClass = _cellClass;

+ (nonnull instancetype)datasourceWithBITableView:(nonnull BITableView *)tableView {
return [self datasourceWithTableView:tableView];
return [super datasourceWithTableView:tableView];
}

#pragma mark - BIDatasourceBase methods
Expand Down
34 changes: 29 additions & 5 deletions BIObjCHelpers/Datasource/TableView/BIDatasourceTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,41 @@

typedef void(^BIDatasourceTableViewConfigureCell)(id __nonnull cell, NSIndexPath * __nonnull indexPath);

@interface BIDatasourceTableView : BIDatasourceBase<UITableViewDataSource>
@interface BIDatasourceTableView : BIDatasourceBase <UITableViewDataSource>

+ (nonnull instancetype)datasourceWithTableView:(nonnull UITableView *)tableView;
- (nonnull instancetype)initWithTableView:(nonnull UITableView *)tableView;
- (nonnull instancetype)init NS_UNAVAILABLE;
+ (nonnull instancetype)new NS_UNAVAILABLE;

@property (nonatomic, readonly, strong, nonnull) UITableView *tableView;
@property (nonatomic, copy, nullable) NSString *cellIdentifier;

@property (nonatomic, strong, nonnull, readonly) UITableView *tableView;
@property (nonatomic, copy, nullable) NSString *cellIdentifier;
@property (nonatomic, strong, nullable) Class cellClass;
@property (nonatomic, copy, nullable) BIDatasourceTableViewConfigureCell configureCellBlock;
@property (nonatomic, copy, nullable) NSInteger(^numberOfRowsInSectionCallback)(NSInteger section);
@property (nonatomic, strong, nullable) UINib *cellNib;
@property (nonatomic, copy, nullable) BIDatasourceTableViewConfigureCell configureCellBlock;
@property (nonatomic, copy, nullable) NSInteger(^numberOfRowsInSectionCallback)(NSInteger section);

- (void)configureCell:(nonnull UITableViewCell *)cell atIndexPath:(nonnull NSIndexPath *)indexPath;

/*!
* @brief Remove cells at a given paths. Use this method instead of tableView's similar one in
* order to better manipulate its stored data.
* @param indexPath Specifies cell that need removing.
* @param animation How to animate the deletion.
*/
- (void)deleteRowsAtIndexPaths:(nonnull NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation;

/*!
* @brief Insert cells at a given indexPaths with a given model objects.
* Use this method instead of tableView's similar one in order to better manipulate its stored data.
* @param indexPath Specifies where cells need to be inserted.
* @param models Model for the cell.
* @param animation How to animate the inserting.
*/
- (void)insertRowsAtIndexPaths:(nonnull NSArray *)indexPaths
models:(nonnull NSArray *)models
withRowAnimation:(UITableViewRowAnimation)animation;

@end
32 changes: 24 additions & 8 deletions BIObjCHelpers/Datasource/TableView/BIDatasourceTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "BIDatasourceTableView.h"
#import "_BITableView+Internal.h"

@interface BIDatasourceTableView ()

Expand All @@ -29,10 +30,27 @@ - (instancetype)initWithTableView:(UITableView *)tableView {
if (self) {
self.tableView = tableView;
self.tableView.dataSource = self;
if ([self.tableView isMemberOfClass:[BITableView class]]) {
BITableView *biTableView = (BITableView *)self.tableView;
biTableView.datasource = self;
}
}
return self;
}

#pragma mark - Public methods

- (void)deleteRowsAtIndexPaths:(nonnull NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation {
[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];
}

- (void)insertRowsAtIndexPaths:(nonnull NSArray *)indexPaths
models:(nonnull NSArray *)models
withRowAnimation:(UITableViewRowAnimation)animation {
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
if (self.configureCellBlock) {
self.configureCellBlock(cell, indexPath);
Expand All @@ -41,7 +59,11 @@ - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPa

- (void)load {
[super load];
[self.tableView registerClass:self.cellClass forCellReuseIdentifier:self.cellIdentifier];
if (self.cellClass) {
[self.tableView registerClass:self.cellClass forCellReuseIdentifier:self.cellIdentifier];
} else if (self.cellNib) {
[self.tableView registerNib:self.cellNib forCellReuseIdentifier:self.cellIdentifier];
}
}

#pragma mark - Property methods
Expand All @@ -53,13 +75,6 @@ - (NSString *)cellIdentifier {
return _cellIdentifier;
}

- (Class)cellClass {
if (!_cellClass) {
_cellClass = [UITableViewCell class];
}
return _cellClass;
}

#pragma mark - UITableViewDataSource Methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
Expand All @@ -71,6 +86,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSAssert(self.cellClass || self.cellNib, @"cellClass or cellNib must be specified");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath: indexPath];
if (!cell) {
cell = [[self.cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:self.cellIdentifier];
Expand Down
2 changes: 2 additions & 0 deletions BIObjCHelpers/Handlers/TableView/BIHandlerTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ typedef void(^BIHandlerTableViewRowSelectionCallback)(id __nonnull cell, NSIndex

+ (nonnull instancetype)handlerWithTableView:(nonnull UITableView *)tableView;
- (nonnull instancetype)initWithTableView:(nonnull UITableView *)tableView;
- (nonnull instancetype)init NS_UNAVAILABLE;
+ (nonnull instancetype)new NS_UNAVAILABLE;

@property (nonatomic, readonly, strong, nonnull) UITableView *tableView;

Expand Down
6 changes: 5 additions & 1 deletion BIObjCHelpers/Handlers/TableView/BIHandlerTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "BIHandlerTableView.h"
#import "_BITableView+Internal.h"

@interface BIHandlerTableView ()

Expand All @@ -28,6 +29,10 @@ - (instancetype)initWithTableView:(UITableView *)tableView {
self = [super init];
if (self) {
self.tableView = tableView;
if ([self.tableView isMemberOfClass:[BITableView class]]) {
BITableView *biTableView = (BITableView *)self.tableView;
biTableView.handler = self;
}
}
return self;
}
Expand All @@ -39,7 +44,6 @@ - (void)load {
self.tableView.delegate = self;
}


#pragma mark - UITableViewDelegate methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Expand Down
3 changes: 3 additions & 0 deletions BIObjCHelpers/Interface/BIObjCHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#import "BIStartersFactory.h"
#import "BIOperationQueue.h"

// Views
#import "BITableView.h"

// Datasources
#import "BIDatasourceTableView.h"
#import "BIDatasourceCollectionView.h"
Expand Down
12 changes: 12 additions & 0 deletions BIObjCHelpers/Views/TableView/BITableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern const CGFloat kBILeadingScreens;
extern const CGFloat kBITableFooterViewAnimationDuration;

@class BIActivityIndicatorContainerView;
@class BIDatasourceTableView;
@class BIHandlerTableView;

/*!
@brief Table view with infinite scrolling support.
Expand Down Expand Up @@ -76,6 +78,16 @@ extern const CGFloat kBITableFooterViewAnimationDuration;

@property (nonatomic, assign) BIInfiniteScrollingState infiniteScrollingState;

/*!
@brief Table view's datasource. Valid only if a BIDatasourceTableView type was created with a reference to this table view.
*/
@property (nonatomic, weak, nullable, readonly) BIDatasourceTableView *datasource;

/*!
@brief Table view's handler. Valid only if a BIHandlerTableView type was created with a reference to this table view.
*/
@property (nonatomic, weak, nullable, readonly) BIHandlerTableView *handler;

- (void)triggerInfiniteScrolling;

@end
4 changes: 3 additions & 1 deletion BIObjCHelpers/Views/TableView/BITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ BOOL BIDisplayShouldFetchBatch(BIScrollDirection scrollDirection,

@interface BITableView () <UITableViewDelegate>

@property (nonatomic, strong, nonnull, readwrite) BIActivityIndicatorContainerView *activityIndicatorContainer;
@property (nonatomic, strong, nonnull, readwrite) BIActivityIndicatorContainerView *activityIndicatorContainer;
@property (nonatomic, strong, nullable, readwrite) _BITableViewProxy *proxyDelegate;
@property (nonatomic, weak, nullable, readwrite) BIDatasourceTableView *datasource;
@property (nonatomic, weak, nullable, readwrite) BIHandlerTableView *handler;

@end

Expand Down
16 changes: 16 additions & 0 deletions BIObjCHelpers/Views/TableView/_BITableView+Internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// BITableView+Internal.h
// BIObjCHelpers
//
// Created by Bogdan Iusco on 17/08/15.
// Copyright (c) 2015 iGama Apps. All rights reserved.
//

#import "BITableView.h"

@interface BITableView (Internal)

@property (nonatomic, weak, nullable, readwrite) BIDatasourceTableView *datasource;
@property (nonatomic, weak, nullable, readwrite) BIHandlerTableView *handler;

@end
16 changes: 16 additions & 0 deletions BIObjCHelpers/Views/TableView/_BITableView+Internal.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// BITableView+Internal.m
// BIObjCHelpers
//
// Created by Bogdan Iusco on 17/08/15.
// Copyright (c) 2015 iGama Apps. All rights reserved.
//

#import "_BITableView+Internal.h"

@implementation BITableView (Internal)

@dynamic datasource;
@dynamic handler;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ @implementation BIDatasourceFeedTableViewTestCase
- (void)setUp {
[super setUp];
self.tableView = [[BITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
self.datasource = [BIMockDatasourceFeedTableView datasourceWithTableView:self.tableView];
self.datasource = [BIMockDatasourceFeedTableView datasourceWithBITableView:self.tableView];
[self.datasource load];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ - (void)setUp {
[super setUp];
self.tableView = [[BITableView alloc] initWithFrame:CGRectZero];
self.datasource = [BIDatasourceFetchedTableView datasourceWithTableView:self.tableView];
self.datasource.cellClass = [UITableViewCell class];
}

- (void)tearDown {
Expand Down
Loading

0 comments on commit 51ed040

Please sign in to comment.