gpt4 book ai didi

iphone - 调整框架大小时 UIScrollView/UITableView 崩溃

转载 作者:行者123 更新时间:2023-12-03 21:10:52 38 4
gpt4 key购买 nike

我的应用程序有一个分页 ScrollView ,每个页面都有一个表格 View 。在屏幕底部,我放置了一个广告横幅,当广告不可用时,该横幅应隐藏,并在加载时重新出现。该横幅放置在 ScrollView 下方,并且不受用户左右滚动页面或上下滚动表格的影响。

因此,我会在需要时使用如下内容调整 ScrollView 的大小:

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 的大小?

最佳答案

这看起来非常像 TableView 数据源的对象被释放,因此委托(delegate)方法被发送到另一个对象。这是一个内存管理问题,因此您可以尝试使用 Zombies 工具运行您的应用程序,看看它是否能解决该问题。

关于iphone - 调整框架大小时 UIScrollView/UITableView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3353077/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com