Skip to content

Commit

Permalink
Avoid crash caused by deallocing parent during scroll
Browse files Browse the repository at this point in the history
Closes #68
  • Loading branch information
michaeltyson committed Aug 8, 2014
1 parent 522ba84 commit cb424fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions TPKeyboardAvoiding/TPKeyboardAvoidingCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ - (void)scrollToActiveTextField {

#pragma mark - Responders, events

-(void)willMoveToSuperview:(UIView *)newSuperview {
[super willMoveToSuperview:newSuperview];
if ( !newSuperview ) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(TPKeyboardAvoiding_assignTextDelegateForViewsBeneathView:) object:self];
}
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self TPKeyboardAvoiding_findFirstResponderBeneathView:self] resignFirstResponder];
[super touchesEnded:touches withEvent:event];
Expand Down
7 changes: 7 additions & 0 deletions TPKeyboardAvoiding/TPKeyboardAvoidingScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ - (void)scrollToActiveTextField {

#pragma mark - Responders, events

-(void)willMoveToSuperview:(UIView *)newSuperview {
[super willMoveToSuperview:newSuperview];
if ( !newSuperview ) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(TPKeyboardAvoiding_assignTextDelegateForViewsBeneathView:) object:self];
}
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self TPKeyboardAvoiding_findFirstResponderBeneathView:self] resignFirstResponder];
[super touchesEnded:touches withEvent:event];
Expand Down
7 changes: 7 additions & 0 deletions TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ - (void)scrollToActiveTextField {

#pragma mark - Responders, events

-(void)willMoveToSuperview:(UIView *)newSuperview {
[super willMoveToSuperview:newSuperview];
if ( !newSuperview ) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(TPKeyboardAvoiding_assignTextDelegateForViewsBeneathView:) object:self];
}
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self TPKeyboardAvoiding_findFirstResponderBeneathView:self] resignFirstResponder];
[super touchesEnded:touches withEvent:event];
Expand Down

1 comment on commit cb424fa

@farri
Copy link

@farri farri commented on cb424fa Jan 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still crash :(

  • (void)TPKeyboardAvoiding_initializeView:(UIView_)view {
    if ( [view isKindOfClass:[UITextField class]] /// here it crashes
    && ((UITextField_)view).returnKeyType == UIReturnKeyDefault
    && (![(UITextField_)view delegate] || [(UITextField_)view delegate] == (id)self) ) {
    [(UITextField*)view setDelegate:(id)self];
    UIView *otherView = nil;
    CGFloat minY = CGFLOAT_MAX;
    [self TPKeyboardAvoiding_findTextFieldAfterTextField:view beneathView:self minY:&minY foundView:&otherView];

    if ( otherView ) {
        ((UITextField*)view).returnKeyType = UIReturnKeyNext;
    } else {
        ((UITextField*)view).returnKeyType = UIReturnKeyDone;
    }
    

    }
    }

Please sign in to comment.