steipete / PSPDFTextView

A subclass of UITextView that fixes the most glaring problems from iOS 7 and 7.1.
http://pspdfkit.com
MIT License
873 stars 73 forks source link

Unrecognized selector crashes #13

Open hpique opened 10 years ago

hpique commented 10 years ago

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?

derpoliuk commented 10 years ago

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.