- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes使用方法

来源:互联网 发布:怎么找淘宝客服介入 编辑:程序博客网 时间:2024/05/16 09:48

 NSMutableArray *targetArray = [NSMutableArray arrayWithCapacity:100];

 - (void)fillInInitially {

            // Add the first set of elements to the beginning of the array

            for (int i =0; i < [initialData count]; ++i)

            {

                [targetArray insertObject:[initialData objectAtIndex:i] atIndex:i];

            }

        }

        

        - (void)fillInTheBlank:(NSArray *) additions {

              // Start adding at index position 28 and current array has 5 items

            NSRange range = NSMakeRange(28, [additions count]);     

            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];

            

            // Can't do this when I'm trying to add 9 new items at index 28

            // because of the error: index 28 beyond bounds [0 .. 5]

            [targetArray insertObjects:additions atIndexes:indexSet];

        }

原创粉丝点击