Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow YLTableViewCell conforming classes to be unregistered #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Classes/YLTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {

- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier {
NSAssert(identifier, @"Must have a reuse identifier.");
NSAssert([cellClass conformsToProtocol:@protocol(YLTableViewCell)], @"You can only use cells conforming to YLTableViewCell.");

[super registerClass:cellClass forCellReuseIdentifier:identifier];

if (cellClass) {
NSAssert([cellClass conformsToProtocol:@protocol(YLTableViewCell)], @"You can only use cells conforming to YLTableViewCell.");

self.cellClassForReuseIdentifier[identifier] = cellClass;
} else {
[self.cellClassForReuseIdentifier removeObjectForKey:identifier];
Expand Down
10 changes: 10 additions & 0 deletions YLTableViewTests/YLTableViewDataSourceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ - (void)testNonConformingCell {
XCTAssertThrows([self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"]);
}

- (void)testUnregistereredTableCell {
NSString *const kUnregisteredReuseIdentifier = @"UnregisteredClass-ReuseId";

[self.tableView registerClass:[YLTableViewCellTestStub class] forCellReuseIdentifier:kUnregisteredReuseIdentifier];
XCTAssertNotNil([self.tableView dequeueReusableCellWithIdentifier:kUnregisteredReuseIdentifier]);

[self.tableView registerClass:nil forCellReuseIdentifier:kUnregisteredReuseIdentifier];
XCTAssertNil([self.tableView dequeueReusableCellWithIdentifier:kUnregisteredReuseIdentifier]);
}

- (void)testEstimatedRowHeightOverride {
self.dataSource.shouldOverrideEstimatedRowHeight = YES;
CGFloat height = [self.dataSource tableView:self.tableView estimatedHeightForRowAtIndexPath:[self _indexPathForCustomReuseIdentifier]];
Expand Down