Ben Packard
Ben Packard

Reputation: 26476

Scrollview continuing to fire scrollViewDidScroll when popped

When I pop a view controller, it is continuing to fire a few rogue scrollViewDidScroll messages. The implementation of this delegate sometimes pulls some entities from my NSManagedObjectContext, which is a property of the object.

However, the context property seems to be nil before the scroll delegate is removed. This leads to those last few scroll delegate messages causing a crash in my application.

I have confirmed this is the root cause by including the following, just before popping the controller:

self.scrollview.delegate = nil

effectively resigning as the delegate. This removes the issue.

Is this the correct procedure? I've never heard of this issue before.

Note: I've had a similar issue with UIPickerView in the past, and resolved it in the same way. Could I be making some design error?

Upvotes: 1

Views: 130

Answers (1)

Hobsie
Hobsie

Reputation: 328

I just hit this exact same issue.

Setting the scrollview.delegate = nil before popping the view fixes the issue for me as well and honestly I don't think it will be a bad thing as it will likely aid garbage collection (I'm using Xamarin, so a slightly different garbage collector). The timing of the garbage collection is probably the root of the issue.

I don't think we're making a design error.

Upvotes: 1

Related Questions