NSMutablearray move object from index to index

前端 未结 7 1030
无人共我
无人共我 2020-12-05 04:05

I have a UItableview with reordable rows and the data is in an NSarray. So how do I move an object in the NSMutablearray when the appropriate tableview delegate is called?

7条回答
  •  不知归路
    2020-12-05 04:11

    id object = [[[self.array objectAtIndex:index] retain] autorelease];
    [self.array removeObjectAtIndex:index];
    [self.array insertObject:object atIndex:newIndex];
    

    That's all. Taking care of the retain count is important, since the array might be the only one referencing the object.

提交回复
热议问题