Nsmutablearray insertobject atindex but move down already inserted objects

坚强是说给别人听的谎言 提交于 2019-12-12 03:19:21

问题


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

Any help appreciated.


回答1:


- (void)insertObject:(id)anObject atIndex:(NSUInteger)index

This method of NSMutableArray is what you are looking for.

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




回答2:


The method you are looking for is: - [NSMutableArray insertObject:atIndex:].

In your example, the index would be 0.



来源:https://stackoverflow.com/questions/9247941/nsmutablearray-insertobject-atindex-but-move-down-already-inserted-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!