tags:

views:

37

answers:

1

Hello everyone

I used codes below to move an 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]];//

}

but it reported:

objc[316]: FREED(id): message retain sent to freed object=0x3d3d330

Welcome any comment

Thanks

interdev

A: 

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]; // <---
KennyTM
KennyTM you are superman! :-)