datwelk / RDRStickyKeyboardView

Please see https://github.com/datwelk/RDRGrowingTextView instead.
MIT License
602 stars 67 forks source link

Crash bug #11

Open Sean-Wang opened 10 years ago

Sean-Wang commented 10 years ago

Added RDRStickyKeyboardView in UITableViewController.

Perform the following steps:

1, Call [self.contentWrapper showKeyboard]; when enter into UITableViewController;

2, Exit UITableViewController;

3, Enter into UITableViewController again;

4, Enter any letter, RDRStickyKeyboardView Crash.

    2014-05-15 16:13:22.479 SW[4854:60b] *** Assertion failure in -[RDRStickyKeyboardView _updateInputViewFrameWithKeyboardFrame:forceReload:](), /Users/venus/github/SW/SW/RDRStickyKeyboardView/RDRStickyKeyboardView.m:917
2014-05-15 16:13:22.502 SW[4854:60b] CRASH: 
2014-05-15 16:13:22.502 SW[4854:60b] Stack Trace: (
    0   CoreFoundation                      0x030fb1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x029db8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x030fb048 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x02687b20 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 101
    4   SW                        0x0022497c -[RDRStickyKeyboardView _updateInputViewFrameWithKeyboardFrame:forceReload:] + 572
    5   SW                        0x00223836 -[RDRStickyKeyboardView _textViewDidChange:] + 134
    6   Foundation                          0x026ae049 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
    7   CoreFoundation                      0x03156f04 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
    8   CoreFoundation                      0x030aeefb _CFXNotificationPost + 2859
    9   Foundation                          0x025e7e41 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
    10  Foundation                          0x025f72ea -[NSNotificationCenter postNotificationName:object:] + 55
    11  UIKit                               0x01da9b6a -[UITextView textInputDidChange:] + 170
    12  UIKit                               0x01dd21b3 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 118
    13  UIKit                               0x01dd4090 -[UITextInputController _insertText:fromKeyboard:] + 768
    14  UIKit                               0x01dd4954 -[UITextInputController insertText:] + 372
    15  UIKit                               0x01da814f -[UITextView insertText:] + 49
    16  UIKit                               0x01887760 -[UIKeyboardImpl insertText:] + 87
    17  UIKit                               0x01898ea4 -[TIKeyboardOperationInsertText(UIKeyboardImpl) main] + 83
    18  Foundation                          0x026afc79 -[__NSOperationInternal _start:] + 671
    19  Foundation                          0x0262c9c8 -[NSOperation start] + 83
    20  UIKit                               0x01885d4d -[UIKeyboardImpl performOperations:] + 153
    21  UIKit                               0x01883f8e -[UIKeyboardImpl continueHandleKeyboardInputWithOperations:] + 75
    22  UIKit                               0x01883ddc __73-[UIKeyboardImpl replyHandlerForHandleKeyboardInputWithExecutionContext:]_block_invoke_2 + 44
    23  UIKit                               0x01ded978 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
    24  UIKit                               0x01dee01f -[UIKeyboardTaskQueue addTask:] + 144
    25  UIKit                               0x01894cc4 -[UIKeyboardImpl handleKeyEvent:] + 227
    26  UIKit                               0x016afcbc -[UIApplication _handleKeyUIEvent:] + 330
    27  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    28  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    29  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    30  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    31  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    32  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    33  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    34  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    35  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    36  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    37  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    38  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    39  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    40  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    41  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    42  UIKit                               0x016afb6b -[UIApplication handleKeyUIEvent:] + 84
    43  UIKit                               0x016afb0f -[UIApplication handleKeyHIDEvent:] + 458
    44  UIKit                               0x01697386 _UIApplicationHandleEventQueue + 3314
    45  CoreFoundation                      0x0308477f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    46  CoreFoundation                      0x0308410b __CFRunLoopDoSources0 + 235
    47  CoreFoundation                      0x030a11ae __CFRunLoopRun + 910
    48  CoreFoundation                      0x030a09d3 CFRunLoopRunSpecific + 467
    49  CoreFoundation                      0x030a07eb CFRunLoopRunInMode + 123
    50  GraphicsServices                    0x04b075ee GSEventRunModal + 192
    51  GraphicsServices                    0x04b0742b GSEventRun + 104
    52  UIKit                               0x0169bf9b UIApplicationMain + 1225
    53  SW                        0x0018b72d main + 141
    54  libdyld.dylib                       0x03c22701 start + 1
)
2014-05-15 16:13:22.505 SW[4854:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: ''
*** First throw call stack:
(
    0   CoreFoundation                      0x030fb1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x029db8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x030fb048 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x02687b20 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 101
    4   SW                        0x0022497c -[RDRStickyKeyboardView _updateInputViewFrameWithKeyboardFrame:forceReload:] + 572
    5   SW                        0x00223836 -[RDRStickyKeyboardView _textViewDidChange:] + 134
    6   Foundation                          0x026ae049 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
    7   CoreFoundation                      0x03156f04 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
    8   CoreFoundation                      0x030aeefb _CFXNotificationPost + 2859
    9   Foundation                          0x025e7e41 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
    10  Foundation                          0x025f72ea -[NSNotificationCenter postNotificationName:object:] + 55
    11  UIKit                               0x01da9b6a -[UITextView textInputDidChange:] + 170
    12  UIKit                               0x01dd21b3 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 118
    13  UIKit                               0x01dd4090 -[UITextInputController _insertText:fromKeyboard:] + 768
    14  UIKit                               0x01dd4954 -[UITextInputController insertText:] + 372
    15  UIKit                               0x01da814f -[UITextView insertText:] + 49
    16  UIKit                               0x01887760 -[UIKeyboardImpl insertText:] + 87
    17  UIKit                               0x01898ea4 -[TIKeyboardOperationInsertText(UIKeyboardImpl) main] + 83
    18  Foundation                          0x026afc79 -[__NSOperationInternal _start:] + 671
    19  Foundation                          0x0262c9c8 -[NSOperation start] + 83
    20  UIKit                               0x01885d4d -[UIKeyboardImpl performOperations:] + 153
    21  UIKit                               0x01883f8e -[UIKeyboardImpl continueHandleKeyboardInputWithOperations:] + 75
    22  UIKit                               0x01883ddc __73-[UIKeyboardImpl replyHandlerForHandleKeyboardInputWithExecutionContext:]_block_invoke_2 + 44
    23  UIKit                               0x01ded978 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
    24  UIKit                               0x01dee01f -[UIKeyboardTaskQueue addTask:] + 144
    25  UIKit                               0x01894cc4 -[UIKeyboardImpl handleKeyEvent:] + 227
    26  UIKit                               0x016afcbc -[UIApplication _handleKeyUIEvent:] + 330
    27  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    28  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    29  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    30  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    31  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    32  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    33  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    34  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    35  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    36  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    37  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    38  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    39  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    40  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    41  UIKit                               0x018021be -[UIResponder(Internal) _handleKeyUIEvent:] + 59
    42  UIKit                               0x016afb6b -[UIApplication handleKeyUIEvent:] + 84
    43  UIKit                               0x016afb0f -[UIApplication handleKeyHIDEvent:] + 458
    44  UIKit                               0x01697386 _UIApplicationHandleEventQueue + 3314
    45  CoreFoundation                      0x0308477f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    46  CoreFoundation                      0x0308410b __CFRunLoopDoSources0 + 235
    47  CoreFoundation                      0x030a11ae __CFRunLoopRun + 910
    48  CoreFoundation                      0x030a09d3 CFRunLoopRunSpecific + 467
    49  CoreFoundation                      0x030a07eb CFRunLoopRunInMode + 123
    50  GraphicsServices                    0x04b075ee GSEventRunModal + 192
    51  GraphicsServices                    0x04b0742b GSEventRun + 104
    52  UIKit                               0x0169bf9b UIApplicationMain + 1225
    53  SW                        0x0018b72d main + 141
    54  libdyld.dylib                       0x03c22701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Sean-Wang commented 10 years ago

@datwelk Please help me fix the problem, thanks.

datwelk commented 10 years ago

You should not use RDRStickyKeyboardView inside a UITableViewController.

datwelk commented 10 years ago

The UITableViewController adds zero value compared to UIViewController, because RDRStickyKeyboardView automatically adjusts the contentOffset of the tableview. Plus, the problem with UITableViewController is that its view property equals its tableview property. If you provide RDRStickyKeyboardView with a UITableViewController's tableview, it will add the tableview as a subview to itself, while it already is a subview of the tableview. See line 569 inside RDRStickyKeyboardView.m.

Sean-Wang commented 10 years ago

I'm sorry. I'd like to set the record straight, I use RDRStickyKeyboardView inside a UIViewController, but UIViewController contain UITableView.

    self.contentWrapper = [[RDRStickyKeyboardView alloc] initWithScrollView:self.commentTableView];
    self.contentWrapper.frame = self.view.bounds;
    self.contentWrapper.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    [self.contentWrapper.inputView.rightButton addTarget:self action:@selector(postCommentToServers) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.contentWrapper];
datwelk commented 10 years ago

You have an example project demonstrating the crash I can take a look at?

Sean-Wang commented 10 years ago

Modify the RDRStickyKeyboardView's demo according to my project process, it works well.

But, if I delete the code in the RDRStickyKeyboardView.m

NSCAssert(!(CGRectEqualToRect(keyboardFrame, CGRectZero) && self.inputViewKeyboard.superview == nil), nil); 

My project will not crash.