Crash when focus on UITextField / UITextView

Discussion in 'iOS Programming' started by Leslie.Hon, Feb 25, 2015.

  1. Leslie.Hon, Feb 25, 2015
    Last edited by a moderator: Feb 25, 2015

    Leslie.Hon macrumors member

    Joined:
    Apr 27, 2008
    Location:
    Hong Kong
    #1
    I have a UITextField which inside a UITableCell in a xib file TableView dequeue the cell, try editing the text field on iOS 7, it work fine.
    When I tested the app in iOS 8, it crash the app and throw the exception below when touching (focus) on the textfield :

    Code:
    -[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7faacacbf110
    1.The custom cell not override any UITableViewCell method and implement any method. The textfield just a UITextField, not override anything.
    2.The textfield work fine when enable Secure Text Entry
    3.Tried load from storyboard, add new text field into View Controller programmatically, but not work.

    Tessted:

    iOS 7.1 (Simulator)
    iOS 8.1.3 (iPhone 5 , Simulator)
    iOS 8.3 beta (Simulator)
     
  2. kage207 macrumors 6502a

    Joined:
    Jul 23, 2008
    #2
    Is the text field at the same memory location as the error message? Looks like you might be sending the wrong selector if that is the memory location of the text field or you are sending it to the wrong object.

    Edit: Hint, are you using objectAtIndex for your text field?
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    I think you need to show more of the stack trace for the crash. I can't tell if the crash is in your code or in UIKit code.
     
  4. Leslie.Hon thread starter macrumors member

    Joined:
    Apr 27, 2008
    Location:
    Hong Kong
    #4

    Here is detail stack trace code


    Code:
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7fa178d58000'
    *** First throw call stack:
    (
      0   CoreFoundation                      0x0000000103319f35 __exceptionPreprocess + 165
      1   libobjc.A.dylib                     0x0000000102fb2bb7 objc_exception_throw + 45
      2   CoreFoundation                      0x000000010332104d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
      3   CoreFoundation                      0x000000010327927c ___forwarding___ + 988
      4   CoreFoundation                      0x0000000103278e18 _CF_forwarding_prep_0 + 120
      5   CoreFoundation                      0x0000000103297ddc CFStringTokenizerCreate + 796
      6   UIKit                               0x0000000102458d58 __91-[_UITextInputControllerTokenizer _getClosestTokenRangeForPosition:granularity:downstream:]_block_invoke44 + 253
      7   UIFoundation                        0x000000010654d06b -[NSTextStorage coordinateReading:] + 42
      8   UIKit                               0x0000000102458a29 -[_UITextInputControllerTokenizer _getClosestTokenRangeForPosition:granularity:downstream:] + 322
      9   UIKit                               0x000000010215479c -[UITextInputStringTokenizer positionFromPosition:toBoundary:inDirection:] + 72
      10  UIKit                               0x0000000102154e4e -[TIDocumentState(UITextInputAdditions) _contextBeforePosition:inDocument:] + 68
      11  UIKit                               0x0000000102154f91 -[TIDocumentState(UITextInputAdditions) initWithDocument:] + 110
      12  UIKit                               0x0000000102154aea +[TIDocumentState(UITextInputAdditions) documentStateOfDocument:] + 50
      13  UIKit                               0x0000000101eeb683 -[UIKeyboardImpl syncDocumentStateToInputDelegateWithExecutionContext:] + 288
      14  UIKit                               0x0000000101eebedb -[UIKeyboardImpl updateForChangedSelectionWithExecutionContext:] + 296
      15  UIKit                               0x0000000102459914 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
      16  UIKit                               0x0000000101ee671f -[UIKeyboardImpl setDelegate:force:] + 2031
      17  UIKit                               0x00000001021b4a12 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 902
      18  UIKit                               0x0000000101e7131d -[UIResponder becomeFirstResponder] + 468
      19  UIKit                               0x0000000101d66e03 -[UIView(Hierarchy) becomeFirstResponder] + 99
      20  UIKit                               0x000000010242dad7 -[UITextField becomeFirstResponder] + 51
      21  UIKit                               0x00000001020b59c1 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 177
      22  UIKit                               0x00000001020b7a30 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2263
      23  UIKit                               0x00000001020ad2e6 _UIGestureRecognizerSendActions + 262
      24  UIKit                               0x00000001020abf89 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
      25  UIKit                               0x00000001020b0ba6 ___UIGestureRecognizerUpdate_block_invoke662 + 51
      26  UIKit                               0x00000001020b0aa2 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
      27  UIKit                               0x00000001020a6b1d _UIGestureRecognizerUpdate + 2796
      28  UIKit                               0x0000000101d40ff6 -[UIWindow _sendGesturesForEvent:] + 1041
      29  UIKit                               0x0000000101d41c23 -[UIWindow sendEvent:] + 667
      30  UIKit                               0x0000000101d0e9b1 -[UIApplication sendEvent:] + 246
      31  UIKit                               0x0000000101d1ba7d _UIApplicationHandleEventFromQueueEvent + 17370
      32  UIKit                               0x0000000101cf7103 _UIApplicationHandleEventQueue + 1961
      33  CoreFoundation                      0x000000010324f551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
      34  CoreFoundation                      0x000000010324541d __CFRunLoopDoSources0 + 269
      35  CoreFoundation                      0x0000000103244a54 __CFRunLoopRun + 868
      36  CoreFoundation                      0x0000000103244486 CFRunLoopRunSpecific + 470
      37  GraphicsServices                    0x00000001051749f0 GSEventRunModal + 161
      38  UIKit                               0x0000000101cfa420 UIApplicationMain + 1282
      39  MyAPP                               0x000000010008a232 main + 178
      40  libdyld.dylib                       0x0000000103943145 start + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb) 
    
     

    Attached Files:

  5. Leslie.Hon thread starter macrumors member

    Joined:
    Apr 27, 2008
    Location:
    Hong Kong
    #5
    I created a new View Controller with only 1 UITextField, still crash :(
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    OK, that's certainly odd. There doesn't seem to be any of your code in the stack trace.

    Are you using ARC?

    Why are you using a nib file and not a storyboard? If you do use a storyboard you should create the cell in the storyboard, not programatically.

    Do you have an IBOutlet for the textfield? Can you show that?

    This kind of error can be caused by a memory management error where an object is released before it should be and its memory location is filled with another object. However that is unlikely to occur if the app uses ARC.

    You say you created a new View Controller, not a table view controller, and added a UITextField and it didn't work. Did you set the delegate property of the text field? How did you add the text field?
     
  7. kage207 macrumors 6502a

    Joined:
    Jul 23, 2008
    #7
    Looks like you are grabbing the wrong object to focus your text field. Have you looked at objectAtIndex for your target action of focus?
     
  8. MGtheGuy, Jun 9, 2015
    Last edited: Jun 9, 2015

    MGtheGuy macrumors newbie

    MGtheGuy

    Joined:
    Jun 9, 2015
    #8
    I also have same problem..
    .. delete the app from your device or simulator and do a fresh install.
    My case, It works~
     

Share This Page