开发者

Specific order NSMutableArray [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Good day.

I have an NSMutableArray that contains references to objects. I need to rearrange the array so that each would-scanned object becomes the last in the array.

For example:

The array has three links to three pictures. Member and one looke开发者_高级运维d out, we save before exiting the index of images viewed

The user has gone back into the program and he has shown a different picture, the one that went beyond that which he looked

A kind of carousel:)

Schematically as follows:

   {Store}      {look last}    {when reload} 
[0], [1], [2] -----> [1] ------> [2], [0], [1] 

[2], [0], [1] -----> [2] ------> [0], [1], [2]

i add object in cycle

for (int i = 0; i < [self.myStorage count]; i++) {
    NSManagedObject *obj = [self.myStorage objectAtIndex:i];
    [self.myArray addObject: obj];
}

and reorder

int last = {get last from core data storage here}
for (int i = 0; i < [self.myArray count]; i++) {
    if(i != last) {
        [self.myArray exchangeObjectAtIndex:i withObjectAtIndex:0];
    }    
}

That is right ?


This is a total guess at what you're asking, but if you want to reorder the array by moving the object selected by the user to the front, then you can simply use the NSMutableArray methods removeObjectAtIndex: and insertObject:atIndex:. I'll elaborate further if you do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜