PSPDFTextView icon indicating copy to clipboard operation
PSPDFTextView copied to clipboard

Unrecognized selector crashes

Open hpique opened this issue 11 years ago • 1 comments

I'm getting "unrecognized selector" crashes in PSPDFTextView.

-[PSPDFTextView scrollViewDidScroll:]: unrecognized selector sent to instance 0x1641f200

These started after implementing scrollViewDidScroll: in the PSPDFTextView/UITextView (real) delegate, a UIViewController. To reproduce, dealloc the UIViewController while still scrolling.

The stack trace:

screen shot 2014-02-23 at 00 53 00

Looks like it might be a delegate forwarding issue, but after looking at the code I'm not exactly sure what might be causing it.

If I add the following to PSPDFTextView the crashes disappear.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([_realDelegate respondsToSelector:@selector(scrollViewDidScroll:)])
    {
        [_realDelegate scrollViewDidScroll:scrollView];
    }
}

However, this is a patch that hides the real issue. Any idea of what it might be?

hpique avatar Feb 23 '14 00:02 hpique

It's not PSPDFTextView issue, it's Cocoa Touch bug (if we can call it this way).

I believe checking [delegate respondsToSelector:@selector(scrollViewDidScroll:)] every time UIScrollView scrolls affects performance. I've got same issue with UITableView. My fix:

- (void)dealloc {
    _tableView.delegate = nil;
}

So for you this fix will be set PSPDFTextView's delegate to nil in your UIViewController dealloc method.

derpoliuk avatar Mar 04 '14 15:03 derpoliuk