xmartlabs / XLForm

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
MIT License
5.78k stars 953 forks source link

Bug Report (NULL) #991

Closed Andy0570 closed 6 years ago

Andy0570 commented 6 years ago

In the official demo of InputsFormViewController.m, add the following code:

#pragma mark - XLFormDescriptorDelegate

- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue {
    [super formRowDescriptorValueHasChanged:formRow oldValue:oldValue newValue:newValue];

    NSString *value = (NSString *)newValue;
    NSLog(@"length = %lu",value.length);
}

When I clear the contents of the input, APP will crash.

2017-10-31 16:48:22.548808+0800 XLForm[10118:5156423] [MC] Reading from public effective user settings.
2017-10-31 16:48:25.172285+0800 XLForm[10118:5156423] length = 1
2017-10-31 16:48:26.075547+0800 XLForm[10118:5156423] length = 2
2017-10-31 16:48:27.385114+0800 XLForm[10118:5156423] length = 3
2017-10-31 16:48:28.739087+0800 XLForm[10118:5156423] length = 2
2017-10-31 16:48:29.381261+0800 XLForm[10118:5156423] length = 1
2017-10-31 16:48:29.932032+0800 XLForm[10118:5156423] -[NSNull length]: unrecognized selector sent to instance 0x1b75ff580
2017-10-31 16:48:29.933512+0800 XLForm[10118:5156423] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x1b75ff580'
*** First throw call stack:
(0x186d5bd38 0x186270528 0x186d691f8 0x186d616e4 0x186c470dc 0x104949ac8 0x1049d5104 0x1876579f0 0x187657518 0x187711324 0x1876569b4 0x18767ab50 0x1049ee930 0x1901a020c 0x1901a018c 0x19018af4c 0x190341f54 0x190341e70 0x1901a9e50 0x1903148d4 0x190387898 0x190387784 0x19038773c 0x190375fb4 0x1905cb284 0x1905ca7a0 0x190e0a9a4 0x190195290 0x18774ba50 0x186d04358 0x186d042d8 0x186d03b60 0x186d01738 0x186c222d8 0x188ab3f84 0x1901cf880 0x10492498c 0x18674656c)
libc++abi.dylib: terminating with uncaught exception of type NSException
santiagofm commented 6 years ago

Well, you can see the cause of the crash in your output. When you clear the input the value of the row gets set to NSNull but formRowDescriptorValueHasChanged: gets also called and you are trying to do value.length... You can fix this issue by checking if newValue is NSNull for example, either way this is an issue with your code rather than with XLForm. Cheers