-5

How to move objects in this array? Tried everything. I cannot select an individual object.

self.images = [NSMutableArray array];
NSFileManager* manager = [NSFileManager new];
NSBundle* bundle = [NSBundle mainBundle];
NSDirectoryEnumerator* enumerator = [manager enumeratorAtPath:[bundle bundlePath]];

for (NSString* name in enumerator) {
    if ([name hasSuffix:@"PawnWhite.png"]) {
        for (int i = 0; i <= 7; i++) {
            UIImage* image = [UIImage imageNamed:name];
            [self.images addObject:image];
        }
    }
}

for (int i = 0; i < self.images.count; i++) {
    CGPoint myPoint = CGPointMake(75.f, 0);

    self.view = [[UIView alloc] initWithFrame:CGRectMake(84.f + myPoint.x * i, 870.f, 75.f, 75.f)];

    self.imagesView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    self.imagesView.image = [self.images objectAtIndex:i];

    [self.view addSubview:self.imagesView];
    [valueView addSubview:self.view];
}

I have pictures in the array, mapped on main view. I need to change any of them that she had changed the location.

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
  • Can you clarify which array you want the objects to be moved into and from where? – Subhash Dike Sep 17 '15 at 14:43
  • That's a funny way to arrange the pieces on a chess board :-/ – trojanfoe Sep 17 '15 at 14:45
  • Your question isn't clear. What is the actual problem you are having with the posted code? – rmaddy Sep 17 '15 at 14:46
  • If I were you, I would delete this question and try again. Are you trying to move the images around on the screen, or change the position of an object from one index of the array to another? Again, don't bother answering here, just make a new question with more details. – Daniel T. Sep 17 '15 at 15:10
  • 1
    @DanielT. 1) Don't suggest deleting. Suggest fixing. 2) You can't delete a question once it has answers. – rmaddy Sep 17 '15 at 15:23

1 Answers1

2

If you want to move objects around within an array - you just remove an item from one location, and add it to another, like this :

[self.images removeObjectAtIndex:index];
[self.images insertObject:object atIndex:newIndex];
Luke Smith
  • 1,218
  • 12
  • 17