UIScrollView Error? float foo = scrollview.zoomScale causes the application to crash

In the viewForZoomingInScrollView: method, from the delegate of my scrollview, I look innocent:

// scrollView is the parameter passed to this method

float foo = scrollView.zoomScale

Boom! Crash, hello gdb.

Is this a known bug? Should I send it?

Cheers, Doug

+4
source share
4 answers

I get this, and I thought it was due to the fact that access to zoomScale ends up calling viewForZoomingInScrollView, which leads to infinite recursion.

But I'm just thinking ...

+7
source

It would be useful to see the result in the xcode debugger console window. Usually, when you get a crash, there is additional information available from the debugger console (the command-shift-R or Run> Console command opens in the menu). If an exception occurs that causes the crash, he will say which one. In either case, you can enter bt (for backtracking) immediately after the failure and see the call column on failure.

In your particular case, it is possible that you accidentally released a UIScrollView object, but still indicated where the old selected object was. This will crash the next time any method is called in UIScrollView , and since zoomScale is a receiver accessory, it is considered a method call. The most obvious symptom of this problem will be the EXC_BAD_ACCESS exception in the debugger console when a failure occurs.

+2
source

Doug thanks for this correction. Why didnโ€™t I think about it? > _ & L;

And as OP said, capturing the zoomScale property launches viewForZoomingInScrollView every time.

Basically, don't use the zoomScale property inside viewForZoomingInScrollView if you do this? CRASH !!!!

+1
source

As the moshi said, the reason this happens is because the zoomScale property includes a viewForZoomingInScrollview call, which causes an endless method call.

0
source

All Articles