Skip to content

Commit 81aca9c

Browse files
bagattemats-claassen
authored andcommitted
Update XLFormRowDescriptor.m to support <Class>.self for custom cells (#1041)
1 parent d8ece14 commit 81aca9c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

XLForm/XL/Descriptors/XLFormRowDescriptor.m

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,42 @@ +(instancetype)formRowDescriptorWithTag:(NSString *)tag rowType:(NSString *)rowT
119119

120120
-(XLFormBaseCell *)cellForFormController:(XLFormViewController * __unused)formController
121121
{
122-
if (!_cell){
122+
if (!_cell) {
123123
id cellClass = self.cellClass ?: [XLFormViewController cellClassesForRowDescriptorTypes][self.rowType];
124+
125+
NSBundle *bundle = [NSBundle mainBundle];
126+
NSString *cellClassString = cellClass;
127+
NSString *cellResource = nil;
128+
124129
NSAssert(cellClass, @"Not defined XLFormRowDescriptorType: %@", self.rowType ?: @"");
130+
125131
if ([cellClass isKindOfClass:[NSString class]]) {
126-
NSString *cellClassString = cellClass;
127-
NSString *cellResource = nil;
128-
NSBundle *bundle = nil;
129132
if ([cellClassString rangeOfString:@"/"].location != NSNotFound) {
130133
NSArray *components = [cellClassString componentsSeparatedByString:@"/"];
131134
cellResource = [components lastObject];
132135
NSString *folderName = [components firstObject];
133136
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:folderName];
134137
bundle = [NSBundle bundleWithPath:bundlePath];
135138
} else {
136-
bundle = [NSBundle bundleForClass:NSClassFromString(cellClass)];
137-
cellResource = cellClassString;
138-
if ([cellClassString rangeOfString:@"."].location != NSNotFound) {
139-
NSArray *components = [cellClassString componentsSeparatedByString:@"."];
140-
cellResource = [components lastObject];
141-
}
142-
}
143-
NSParameterAssert(bundle != nil);
144-
NSParameterAssert(cellResource != nil);
145-
146-
if ([bundle pathForResource:cellResource ofType:@"nib"]){
147-
_cell = [[bundle loadNibNamed:cellResource owner:nil options:nil] firstObject];
139+
cellResource = [cellClassString componentsSeparatedByString:@"."].lastObject;
148140
}
141+
} else {
142+
cellResource = [NSStringFromClass(cellClass) componentsSeparatedByString:@"."].lastObject;
143+
}
144+
145+
if ([bundle pathForResource:cellResource ofType:@"nib"]) {
146+
_cell = [[bundle loadNibNamed:cellResource owner:nil options:nil] firstObject];
149147
} else {
150148
_cell = [[cellClass alloc] initWithStyle:self.cellStyle reuseIdentifier:nil];
151149
}
150+
152151
_cell.rowDescriptor = self;
152+
153153
NSAssert([_cell isKindOfClass:[XLFormBaseCell class]], @"UITableViewCell must extend from XLFormBaseCell");
154+
154155
[self configureCellAtCreationTime];
155156
}
157+
156158
return _cell;
157159
}
158160

0 commit comments

Comments
 (0)