NSMutablearray将对象从索引移到索引 [英] NSMutablearray move object from index to index

查看:63
本文介绍了NSMutablearray将对象从索引移到索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有可调整行的UItableview,数据在NSarray中.那么,当调用适当的tableview委托时,如何在NSMutablearray中移动对象?

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?

另一种询问方式是如何对NSMutableArray重新排序?

Another way to ask this is how to reorder an NSMutableArray?

推荐答案

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.

这篇关于NSMutablearray将对象从索引移到索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆