Darkseal / DownPicker

A lightweight DropDownList / ComboBox for iOS, written in Objective-C
MIT License
202 stars 93 forks source link

"exceeds maximum index value of NSNotFound - 1" #11

Closed WedgeSparda closed 8 years ago

WedgeSparda commented 8 years ago

Just created a picker with this

self.transactionTypes = [[NSMutableArray alloc] initWithArray:@[@"Buy", @"Rent", @"Share"]];
self.transactionTypePicker = [[DownPicker alloc] initWithTextField:self.transactionTypeField
                                                              withData:self.transactionTypes];

Then, when I selected the DropDown, got this error

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableIndexSet addIndexesInRange:]: Range {2147483647, 1} exceeds maximum index value of NSNotFound - 1'
*** First throw call stack:
(
    0   CoreFoundation                      0x01bdb1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0195a8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01bdafbb +[NSException raise:format:] + 139
    3   Foundation                          0x01588b1b -[NSMutableIndexSet addIndexesInRange:] + 123
    4   Foundation                          0x015afbbb -[NSMutableIndexSet addIndex:] + 48
    5   UIKit                               0x00b6d089 -[UIPickerTableView selectRow:animated:notify:] + 233
    6   UIKit                               0x00c85cdf -[UIPickerColumnView selectRow:animated:notify:] + 65
    7   UIKit                               0x0060bb51 -[UIPickerView _selectRow:inComponent:animated:notify:] + 165
    8   UIKit                               0x0060bbdf -[UIPickerView selectRow:inComponent:animated:] + 63
    9   Immogeo                             0x000718f8 -[DownPicker showPicker:] + 568
    10  Immogeo                             0x00071bf1 -[DownPicker textFieldShouldBeginEditing:] + 129
    11  UIKit                               0x00d38dcb -[UITextField canBecomeFirstResponder] + 248
    12  UIKit                               0x00781045 -[UIResponder(Internal) _canBecomeFirstResponder] + 33
    13  UIKit                               0x00780017 -[UIResponder becomeFirstResponder] + 242
    14  UIKit                               0x0067b60e -[UIView(Hierarchy) becomeFirstResponder] + 114
    15  UIKit                               0x00d3906a -[UITextField becomeFirstResponder] + 51
    16  UIKit                               0x009bfbff -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 197
    17  UIKit                               0x009c21d2 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2640
    18  UIKit                               0x009b64f4 _UIGestureRecognizerSendActions + 230
    19  UIKit                               0x009b5168 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
    20  UIKit                               0x009b6bdd -[UIGestureRecognizer _delayedUpdateGesture] + 60
    21  UIKit                               0x009ba13d ___UIGestureRecognizerUpdate_block_invoke + 57
    22  UIKit                               0x009ba0be _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
    23  UIKit                               0x009b07ac _UIGestureRecognizerUpdate + 199
    24  UIKit                               0x0065ba5a -[UIWindow _sendGesturesForEvent:] + 1291
    25  UIKit                               0x0065c971 -[UIWindow sendEvent:] + 1021
    26  UIKit                               0x0062e5f2 -[UIApplication sendEvent:] + 242
    27  UIKit                               0x00618353 _UIApplicationHandleEventQueue + 11455
    28  CoreFoundation                      0x01b6477f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    29  CoreFoundation                      0x01b6410b __CFRunLoopDoSources0 + 235
    30  CoreFoundation                      0x01b811ae __CFRunLoopRun + 910
    31  CoreFoundation                      0x01b809d3 CFRunLoopRunSpecific + 467
    32  CoreFoundation                      0x01b807eb CFRunLoopRunInMode + 123
    33  GraphicsServices                    0x038f95ee GSEventRunModal + 192
    34  GraphicsServices                    0x038f942b GSEventRun + 104
    35  UIKit                               0x0061af9b UIApplicationMain + 1225
    36  Immogeo                             0x000708aa main + 138
    37  libdyld.dylib                       0x022216d9 start + 1
)

EDIT: I just found out that the problem occurs when there is some text in the Text Field (set in the Storyboard) so, in this lines was where the error shows up.

    //If the text field is empty show the place holder otherwise show the last selected option
    if (self->textField.text.length == 0)
    {
      self->textField.placeholder = self->placeholderWhileSelecting;
    }
    else
    {
      [self->pickerView selectRow:[self->dataArray indexOfObject:self->textField.text] inComponent:0 animated:YES];
    }
Darkseal commented 8 years ago

Committed into master branch. Thank you for helping me making a better lib :)