Skip to content

Commit cb424fa

Browse files
committed
Avoid crash caused by deallocing parent during scroll
Closes #68
1 parent 522ba84 commit cb424fa

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

TPKeyboardAvoiding/TPKeyboardAvoidingCollectionView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ - (void)scrollToActiveTextField {
6767

6868
#pragma mark - Responders, events
6969

70+
-(void)willMoveToSuperview:(UIView *)newSuperview {
71+
[super willMoveToSuperview:newSuperview];
72+
if ( !newSuperview ) {
73+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(TPKeyboardAvoiding_assignTextDelegateForViewsBeneathView:) object:self];
74+
}
75+
}
76+
7077
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
7178
[[self TPKeyboardAvoiding_findFirstResponderBeneathView:self] resignFirstResponder];
7279
[super touchesEnded:touches withEvent:event];

TPKeyboardAvoiding/TPKeyboardAvoidingScrollView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ - (void)scrollToActiveTextField {
6060

6161
#pragma mark - Responders, events
6262

63+
-(void)willMoveToSuperview:(UIView *)newSuperview {
64+
[super willMoveToSuperview:newSuperview];
65+
if ( !newSuperview ) {
66+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(TPKeyboardAvoiding_assignTextDelegateForViewsBeneathView:) object:self];
67+
}
68+
}
69+
6370
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
6471
[[self TPKeyboardAvoiding_findFirstResponderBeneathView:self] resignFirstResponder];
6572
[super touchesEnded:touches withEvent:event];

TPKeyboardAvoiding/TPKeyboardAvoidingTableView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ - (void)scrollToActiveTextField {
6262

6363
#pragma mark - Responders, events
6464

65+
-(void)willMoveToSuperview:(UIView *)newSuperview {
66+
[super willMoveToSuperview:newSuperview];
67+
if ( !newSuperview ) {
68+
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(TPKeyboardAvoiding_assignTextDelegateForViewsBeneathView:) object:self];
69+
}
70+
}
71+
6572
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
6673
[[self TPKeyboardAvoiding_findFirstResponderBeneathView:self] resignFirstResponder];
6774
[super touchesEnded:touches withEvent:event];

0 commit comments

Comments
 (0)