我使用下面的代码来移动UITableCell
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSMyObj *newObj=[myArray objectAtIndex:[fromIndexPath row]] ;//myArray is the array to store NSMyObj
[myArray removeObjectAtIndex:[fromIndexPath row]];
[myArray insertObject:newObj atIndex:[toIndexPath row]];//
}
但它报告说:
objc [316]:FREED(id):消息保留发送到释放对象= 0x3d3d330
欢迎任何评论
由于
InterDev中
答案 0 :(得分:0)
您必须暂时-retain
newObj,以避免它变为无主人并取消分配。
NSMyObj *newObj = [[myArray objectAtIndex:[fromIndexPath row]] retain]; // <---
[myArray removeObjectAtIndex:[fromIndexPath row]];
[myArray insertObject:newObj atIndex:[toIndexPath row]];
[newObj release]; // <---