NSMutableArray add object with order

前端 未结 3 840
猫巷女王i
猫巷女王i 2021-01-30 12:50

I have a NSMUtableArray which has elements, for example:

a,b,c,e

And I want to add an object d to behind c and befor

3条回答
  •  失恋的感觉
    2021-01-30 13:11

    To inject element to known index (position) use

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

    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html

    And to find position of object previously placed into NSMutableArray use

    - (int)indexOfObject:(id)anObject
    

    NSMutableArray - Get Arrays Index Integer By Searching With A String

    Section Finding Objects in an Array
    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html

提交回复
热议问题