0

我有以下代码尝试设置 GridView,并且我有一个管理数据源的 GridviewController 子类。这是用于设置它的代码。

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

但是,应用程序在尝试访问数据源时会崩溃。这是尝试调用该方法并使其崩溃的行(在 Gridview 类中):

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

错误是 exc_bad_access。可能是什么问题呢?是因为对象被释放得太早了吗?我该如何纠正它?

4

1 回答 1

0

你是对的; 问题很可能是您NUBMyCpGridviewController正在被释放。根据您的代码片段,似乎没有人保留它。

我的建议是让它成为strong @property你的代码片段正在执行的任何类。

于 2012-03-07T09:45:04.210 回答