简体   繁体   English

使用GridView使用exc_bad_access,可能的内存管理失败了吗?

[英]exc_bad_access with GridView, possible memory management fail?

I have the following code that tries to set up a GridView and I have a GridviewController subclass that manages the datasource. 我有以下代码尝试设置GridView,并且我有一个GridviewController子类来管理数据源。 This is the code that is used to set it up. 这是用于设置它的代码。

            AQGridView* gridView = [[AQGridView alloc] initWithFrame:frame];
            NUBMyCpGridviewController* controller = [[NUBMyCpGridviewController alloc] init];
            gridView.dataSource = controller;
            gridView.delegate = controller;
            [gridView reloadData];

However, the app crashes when it tries to access the datasource. 但是,该应用程序在尝试访问数据源时崩溃。 This is the line (in the Gridview class) that gives the tries to call the method and crashes it: 这是在Gridview类中的行,它尝试调用该方法并将其崩溃:

AQGridViewCell * cell = [_dataSource gridView: self cellForItemAtIndex: index];

The error is exc_bad_access. 错误是exc_bad_access。 What could be the problem? 可能是什么问题呢? Is it because the object is being released too early? 是因为对象发布得太早了吗? How can I rectify it? 我该如何纠正?

You're right; 你是对的; the problem is most likely that your NUBMyCpGridviewController is being deallocated. 该问题很可能是您的NUBMyCpGridviewController被释放了。 Based on your code snippet it looks like no one is retaining it. 根据您的代码片段,似乎没有人保留它。

My suggestion would be to make it a strong @property of whichever class your snippet code is being executed in. 我的建议是使其成为要在其片段代码中执行的任何类的strong @property

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM