问题描述
我想问一下以下场景是否有可能发生.我有一个 Nsmutablearray,里面有 5 个对象.我在 uitableview 上加载 Nsmutablearray.我想在其他五个对象的顶部插入一个新对象,但也将所有先前插入的对象向下移动一个.我给你举个例子
I wanted to ask if the following scenario is somehow possible to happen.I have an Nsmutablearray and i have in it 5 objects. I load the Nsmutablearray on an uitableview. I want to insert a new object at the top of the other five objects but also move down all the previously inserted objects down by one. let me give you an example
0 one
1 two
2 three
3 four
4 five
我想在顶部插入新对象后得到这样的结果
i want to result like this after the new object inserted on the top
0 six
1 one
2 two
3 three
4 four
5 five
感谢任何帮助.
推荐答案
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index
NSMutableArray
的这个方法就是你要找的.
This method of NSMutableArray
is what you are looking for.
如果索引已被占用,索引处及之后的对象将通过将1添加到它们的索引中以腾出空间来移动.
这篇关于Nsmutablearray 在索引处插入对象但向下移动已经插入的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!