具体顺序 NSMutableArray

发布于 2024-12-09 04:22:46 字数 896 浏览 0 评论 0原文

再会。

我有一个 NSMutableArray,其中包含对对象的引用。 我需要重新排列数组,以便每个要扫描的对象成为数组中的最后一个。

例如:

该数组具有指向三张图片的三个链接。会员和一个看起来 出,我们在退出之前保存查看的图像索引

用户已返回程序,并且他显示了不同的内容 照片,那张超出了他看上去的照片

一种轮播:)

示意图如下:

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

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

我在循环中添加对象

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

并重新排序

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];
    }    
}

这是对的吗?

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 looked
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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半暖夏伤 2024-12-16 04:22:46

这完全是对您所问问题的猜测,但是如果您想通过将用户选择的对象移动到前面来重新排序数组,那么您可以简单地使用 NSMutableArray 方法removeObjectAtIndex:insertObject:atIndex:。如果您愿意,我会进一步详细说明。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文