rsattar / CLTokenInputView

A replica of iOS's native contact bubbles UI
MIT License
504 stars 127 forks source link

Crash when hitting backspace #14

Closed christ776 closed 8 years ago

christ776 commented 8 years ago

Hi guys,

I'm having a weird crash, when hitting backspace and having at least one token view.

Here's the crash.

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x7f9241d61490> should have parent view controller:<ContactsSelectionViewController: 0x7f9241cbbc80> but requested parent is:<UIInputWindowController: 0x7f924201ac00>'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010b538f45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010af89deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010b538e7d +[NSException raise:format:] + 205
    3   UIKit                               0x0000000109760f50 -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 321
    4   UIKit                               0x0000000109f17845 -[UIInputWindowController changeToInputViewSet:] + 473
    5   UIKit                               0x0000000109f18ad8 __43-[UIInputWindowController setInputViewSet:]_block_invoke_21239 + 39
    6   UIKit                               0x0000000109f10806 -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 369
    7   UIKit                               0x0000000109f18aab __43-[UIInputWindowController setInputViewSet:]_block_invoke1238 + 98
    8   UIKit                               0x0000000109f0c968 -[UIInputWindowController performOperations:withTemplateNotificationInfo:] + 42
    9   UIKit                               0x0000000109f18765 -[UIInputWindowController setInputViewSet:] + 1194
    10  UIKit                               0x0000000109f1048e -[UIInputWindowController performOperations:withAnimationStyle:] + 50
    11  UIKit                               0x0000000109c1ad85 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1179
    12  UIKit                               0x00000001097d6bc1 -[UIResponder(UIResponderInputViewAdditions) reloadInputViews] + 81
    13  UIKit                               0x00000001097d3bea -[UIResponder becomeFirstResponder] + 617
    14  UIKit                               0x000000010966da1b -[UIView(Hierarchy) becomeFirstResponder] + 138
    15  hyp                                 0x00000001054d0ded -[CLTokenView setSelected:animated:] + 125
    16  hyp                                 0x00000001054ce33e -[CLTokenInputView selectTokenView:animated:] + 142
    17  hyp                                 0x00000001054cd920 __48-[CLTokenInputView textFieldDidDeleteBackwards:]_block_invoke + 240

Basically it's triggered at [self becomeFirstResponder]; in

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (_selected == selected) {
        return;
    }
    _selected = selected;

    if (selected) {
        [self becomeFirstResponder];
    }
    CGFloat selectedAlpha = (_selected ? 1.0 : 0.0);
    if (animated) {
        if (_selected) {
            self.selectedBackgroundView.alpha = 0.0;
            self.selectedBackgroundView.hidden = NO;
            self.selectedLabel.alpha = 0.0;
            self.selectedLabel.hidden = NO;
        }
        [UIView animateWithDuration:0.25 animations:^{
            self.selectedBackgroundView.alpha = selectedAlpha;
            self.selectedLabel.alpha = selectedAlpha;
        } completion:^(BOOL finished) {
            if (!_selected) {
                self.selectedBackgroundView.hidden = YES;
                self.selectedLabel.hidden = YES;
            }
        }];
    } else {
        self.selectedBackgroundView.hidden = !_selected;
        self.selectedLabel.hidden = !_selected;
    }
}

Any ideas? thanks !

christ776 commented 8 years ago

turns out, I had added a property called inputView to my ViewController ... without realizing it's an actual property !