【发布时间】:2011-07-02 11:53:43
【问题描述】:
当程序获取最后一行时,我正在尝试在 tableView 中加载接下来的 10 行数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我正在使用带有 pagenumber 参数的单个函数来加载连续页面。 它适用于第一次获取,即页码 0,但是当我再次调用它来获取下一页行时,它给了我这个错误
-[CFString respondsToSelector:]: message sent to deallocated instance
敲了很长时间后,我发现它在尝试访问我的模型对象的 NSMutableArray 时会产生这个问题。 我就是这样用的:
TableRowObjectClass* TempObject = [[TableRowObject alloc] init];
for(int i=0;i<rowArray.count;i++){
TempObject = [rowArray objectAtIndex:i];
NSString* objectProperty = [[[NSString alloc] initWithFormat:@"String Property I need from Object to be appended with some text from TableRowObject Class : %@",TempObject.objProperty] retain];
[propertyArray addObject:objectProperty];
[objectProperty release];
}
在这里,我得到了模型对象数组(TableRowObjectClass 的对象),我想从 TempObject 中提取 objectProperty 并创建所有这些属性的数组。
最初,对于pagenumber 0,它获取 20 行,现在当我显示第 20 行时,我调用 fetch,它调用此函数来创建 objectProperty 的新数组,我调用 [TableView reloadData] 以显示带有 20 的 frsh 提要(旧)+20(新鲜)Feed。
现在它创建了这个错误
-[CFString respondsToSelector:]: message sent to deallocated instance
尝试访问时,
NSString* objectProperty = [[[NSString alloc] initWithFormat:@"String Property ....TableRowObject Class: %@",TempObject.objProperty] retain];
我不确定dealloc 是什么以及在哪里得到的。
我在这方面花了很多时间,但我对 Objective-C 内存管理并不是很擅长。
非常感谢您的帮助。
【问题讨论】:
-
TableRowObject 是类还是变量?你似乎同时使用它。
-
它是一个有自己的 init 方法的类。它的对象是通过解析 JSON 数据创建的,并在这些对象的 NSMutable 数组中返回。
-
感谢您指出这一点,我在上面的帖子中修复了它。这不是实际的代码。 (无法粘贴确切的代码,公司政策)我正在尝试展示功能,这与现在上面提供的代码类似。
标签: iphone objective-c uitableview memory-management memory-leaks