move UITableCell
I used codes below to move an UITableCell
- (void)tabl开发者_JAVA百科eView:(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]];//
}
but it reported:
objc[316]: FREED(id): message retain sent to freed object=0x3d3d330
Welcome any comment
Thanks
interdev
You have to temporarily -retain
the newObj to avoid it becoming owner-less and deallocated.
NSMyObj *newObj = [[myArray objectAtIndex:[fromIndexPath row]] retain]; // <---
[myArray removeObjectAtIndex:[fromIndexPath row]];
[myArray insertObject:newObj atIndex:[toIndexPath row]];
[newObj release]; // <---
精彩评论