开发者

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]; // <---
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜