Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

objective c - Nsmutablearray insertobject atindex but move down already inserted objects

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
- (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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...