NSArray 到 CALayerArray

发布于 2024-12-04 12:14:31 字数 217 浏览 3 评论 0原文

我有一个问题,我无法弄清楚发生了什么

我有一个表视图,并且我有一个名为 newsData 的属性。 我设置了一切并且工作正常! 然后在模拟器中我调用内存警告来查看应用程序如何工作。 我可以看到 tableview 正在被释放,当我回调 viewdidload 时,我可以看到这个数组现在是类 CALayerArray! 当我尝试访问它时,我的程序崩溃了!

到底是怎么回事? 感谢您的帮助。

I have a problem and I cannot figure out what is going on

I have a tableview and I have a property names newsData.
I setup everything and its working fine!
Then in the simulator I call memory warning to see how the app is working.
I can see that the tableview is being released and when I call back the viewdidload I can see that this array is now class CALayerArray!!!
When I try to access it my program crashes!

What is going on?
Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何处潇湘 2024-12-11 12:14:31

您是否在 viewdidload 调用中重新分配了 tableview?发布后,您需要执行此操作。您可能希望在释放 tableView 后将其设置为 nil,以避免崩溃(这仍然需要您在释放 tableView 后重新分配并初始化它!)

 [tableView release];
 tableView = nil;

澄清:我的意思不是,您需要在释放后将任何对象设置为 nil释放了!但是释放它之后,你应该知道该对象已经被释放了!

Have you reallocated tableview within the viewdidload call? After you released it you need to do that. You might want to set your tableView nil after releasing it, in order to avoid the crashes (This still requires you to reallocate and initialize the tableView after you released it!)

 [tableView release];
 tableView = nil;

Clearification: I dont mean, you need to set any object nil after you released it! But after releasing it, you should be aware of the object being already released!

君勿笑 2024-12-11 12:14:31

根据代码的不同,造成这种情况的可能原因有很多。首先,当你说“我有一个表视图并且我有一个名为 newsData 的属性”时,我很困惑。 newsData 属于什么对象?您是否子类化了 UITableView,或者您的意思是这是您的 UITableViewDataSource 的 ivar?

什么是新闻数据?这听起来应该是一个 NSData,但你是说它是一个 NSArray 吗?

您应该首先审核分配 newsData 的所有位置。在大多数情况下,我会说你将它分配给不返回 NSArray 的东西。我对此表示怀疑,因为 CALayerArray 是私有的。这看起来更像是您正在访问正在用于其他用途的内存。我会检查您的内存警告代码和 viewDidUnload: 代码并运行静态分析器作为开始。

There are many possible causes for this depending on the code. First, I'm confused when you say "I have a tableview and I have a property names newsData." What object does newsData belong to? Did you subclass UITableView, or do you mean this is an ivar of your UITableViewDataSource?

What is newsData? This sounds like it should be an NSData, but are you saying that it's an NSArray?

You should first audit everywhere you assign newsData. In most cases I would say you're assigning it to something that does not return an NSArray. I doubt that in this case because CALayerArray is private. This looks more like you're accessing memory that's being used for something else. I would check your memory warning code and your viewDidUnload: code and run the static analyzer as a start.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文