Nsmutablearray 在索引处插入对象但向下移动已经插入的对象 [英] Nsmutablearray insertobject atindex but move down already inserted objects

查看:23
本文介绍了Nsmutablearray 在索引处插入对象但向下移动已经插入的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下以下场景是否有可能发生.我有一个 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添加到它们的索引中以腾出空间来移动.

If index is already occupied, the objects at index and beyond are shifted by adding 1 to their indices to make room.

这篇关于Nsmutablearray 在索引处插入对象但向下移动已经插入的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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