具体顺序 NSMutableArray
再会。
我有一个 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 viewedThe user has gone back into the program and he has shown a different
picture, the one that went beyond that which he lookedA 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这完全是对您所问问题的猜测,但是如果您想通过将用户选择的对象移动到前面来重新排序数组,那么您可以简单地使用
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
methodsremoveObjectAtIndex:
andinsertObject:atIndex:
. I'll elaborate further if you do.