App crashes using custom rows with xib file in iOS 11.X - Swift
bagatte opened this issue · 3 comments
Applications using XLForm
running on iOS 11.X are crashing when using custom rows. After downloading the examples from https://github.com/xmartlabs/XLForm/tree/master/Examples/Swift, and trying to test Custom Rows, I've realized that the crash happens at XLFormRowDescriptor.cellForFormController(::)
at line 136.
bundle = [NSBundle bundleForClass:NSClassFromString(cellClass)];
In this case it happens because XLFormRatingCell.swift
and XLFormWeekDaysCell.swift
, which inherit from XLFormBaseCell
use a xib
file for the cell.
NOTE It doesn't happen when running the app in the simulator.
-(XLFormBaseCell *)cellForFormController:(XLFormViewController * __unused)formController
{
if (!_cell){
id cellClass = self.cellClass ?: [XLFormViewController cellClassesForRowDescriptorTypes][self.rowType];
NSAssert(cellClass, @"Not defined XLFormRowDescriptorType: %@", self.rowType ?: @"");
if ([cellClass isKindOfClass:[NSString class]]) {
NSString *cellClassString = cellClass;
NSString *cellResource = nil;
NSBundle *bundle = nil;
if ([cellClassString rangeOfString:@"/"].location != NSNotFound) {
NSArray *components = [cellClassString componentsSeparatedByString:@"/"];
cellResource = [components lastObject];
NSString *folderName = [components firstObject];
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:folderName];
bundle = [NSBundle bundleWithPath:bundlePath];
} else {
bundle = [NSBundle bundleForClass:NSClassFromString(cellClass)]; // IT CRASHES HERE
cellResource = cellClassString;
}
NSParameterAssert(bundle != nil);
NSParameterAssert(cellResource != nil);
if ([bundle pathForResource:cellResource ofType:@"nib"]){
_cell = [[bundle loadNibNamed:cellResource owner:nil options:nil] firstObject];
}
} else {
_cell = [[cellClass alloc] initWithStyle:self.cellStyle reuseIdentifier:nil];
}
_cell.rowDescriptor = self;
NSAssert([_cell isKindOfClass:[XLFormBaseCell class]], @"UITableViewCell must extend from XLFormBaseCell");
[self configureCellAtCreationTime];
}
return _cell;
}
@bagatte Which is the crash?
Also, to confirm, this crash only happens in iOS 11, not iOS 12 nor 10?
I had it on an iPad running iOS 9.3.5
Merged the PR. Thanks for contributing!