当调整框架大小时,UIScrollView/UITableView崩溃
问题描述:
我的应用程序在每个页面中都有一个带有tableView的分页滚动视图。在屏幕的底部,我放置了一个广告横幅,当广告不可用时它应该隐藏起来,并在加载时重新出现。此横幅放置在scrollView下方,不受用户左右滚动页面或上下滚动表格的影响。当调整框架大小时,UIScrollView/UITableView崩溃
所以我调整是随时滚动视图的东西需要的是这样的:
NSInteger offset = -50;
if (self.bannerIsVisible) offset = 50;
CGRect frame = scrollView.frame;
frame.size.height += offset;
scrollView.contentSize = CGSizeMake(frame.size.width * pages, frame.size.height);
scrollView.frame = frame;
最后一行是造成我的问题。有时候一切正常,它可以完美调整scrollView及其内容。其他时候,它这个崩溃控制台:
2010-07-27 10:25:31.779 MyAPP[8026:207] -[__NSArrayM tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x736eb20
2010-07-27 10:25:31.781 MyAPP[8026:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x736eb20'
*** Call stack at first throw:
(
0 CoreFoundation 0x026cb919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x028195de objc_exception_throw + 47
2 CoreFoundation 0x026cd42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0263d116 ___forwarding___ + 966
4 CoreFoundation 0x0263ccd2 _CF_forwarding_prep_0 + 50
5 UIKit 0x003a3a3f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 619
6 UIKit 0x00399ad2 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
7 UIKit 0x003ae40c -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
8 UIKit 0x003a60d7 -[UITableView(_UITableViewPrivate) _setNeedsVisibleCellsUpdate:withFrames:] + 372
9 UIKit 0x003a37cd -[UITableView setFrame:] + 266
10 UIKit 0x00367ae8 -[UIView(Geometry) resizeWithOldSuperviewSize:] + 385
11 UIKit 0x0036ba2b -[UIView(Geometry) resizeSubviewsWithOldSize:] + 273
12 UIKit 0x00367f79 -[UIView(Geometry) setFrame:] + 497
13 UIKit 0x0038085f -[UIScrollView setFrame:] + 617
14 MyAPP 0x0000a678 -[MyViewController toggleBanner] + 893
这究竟是为什么,为什么只是有时?更重要的是,我怎样才能可靠地改变我的scrollView的大小?
答
看起来非常像您的表视图的数据源被释放的对象,因此委托方法被发送到不同的对象。这是一个内存管理问题,所以你可以尝试使用僵尸工具运行你的应用程序,看看它是否会发现问题。
您是否尝试过逐步调试表格cellForRowAtIndexPath方法?从我的角度来看,这种方法似乎有一个无效的呼叫。不是100%确定艰难。 – samsam 2010-07-28 14:30:02