UIScrollView setContentSize与未捕获的NSRangeException崩溃 [英] UIScrollView setContentSize crashes with uncaught NSRangeException

查看:261
本文介绍了UIScrollView setContentSize与未捕获的NSRangeException崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在删除了一些UIScrollView的内容后,调用setContentSize会导致应用程序崩溃。

Call to setContentSize crashes the application after some of the UIScrollView's contents have been removed.

int toolbarHeight = [[[self navigationController] toolbar] frame].size.height;
int navbarHeight = [[[self navigationController] navigationBar] frame].size.height;

int totalHeight = toolbarHeight + navbarHeight;
// contentWidth is 640
CGSize contentSize = CGSizeMake(contentWidth, [scrollView frame].size.height - totalHeight);

[scrollView setContentSize:contentSize]; // Crash happens here, contentSize is perfectly valid




由于未捕获异常NSRangeException而终止应用程序,原因:'* - [__ NSArrayM objectAtIndex:]:index 1超出边界[0 ..
0]'

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

这可能是什么原因造成的?

What could be causing this?

EDIT 可以有任何意义:

* thread #1: tid = 0x1c03, 0x34d2e32c libsystem_kernel.dylib`__pthread_kill + 8, stop reason    = signal SIGABRT
frame #0: 0x34d2e32c libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x36c2a20e libsystem_c.dylib`pthread_kill + 54
frame #2: 0x36c2329e libsystem_c.dylib`abort + 94
frame #3: 0x308eff6a libc++abi.dylib`abort_message + 46
frame #4: 0x308ed34c libc++abi.dylib`_ZL17default_terminatev + 24
frame #5: 0x36361356 libobjc.A.dylib`_objc_terminate + 146
frame #6: 0x308ed3c4 libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 76
frame #7: 0x308ed450 libc++abi.dylib`std::terminate() + 20
frame #8: 0x308ee824 libc++abi.dylib`__cxa_rethrow + 88
frame #9: 0x363612a8 libobjc.A.dylib`objc_exception_rethrow + 12
frame #10: 0x34e9050c CoreFoundation`CFRunLoopRunSpecific + 404
frame #11: 0x34e9036c CoreFoundation`CFRunLoopRunInMode + 104
frame #12: 0x3618c438 GraphicsServices`GSEventRunModal + 136
frame #13: 0x31f86e7c UIKit`UIApplicationMain + 1080
frame #14: 0x0000cb50 App`main + 152 at main.m:16


推荐答案

看起来当内容偏移量超出内容大小时抛出异常。

It seems that the exception is thrown when the content offset is left outside the content size.

I had views side by side in the scroll view and the offset was to the last view.

+------+------+------+
|      |      |offset|
+------+------+------+

Now the last view is removed and the content size changed to a smaller one.

+------+------+
|      |      |offset
+------+------+

The offset is left behind.

我更改了代码,以便先移动偏移量,然后更改内容大小。

I changed the code so that the offset is moved first, then the content size changed.

+------+------+
|      |offset|
+------+------+

没有崩溃到目前为止。

这篇关于UIScrollView setContentSize与未捕获的NSRangeException崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆