Monday, 19 August 2013

Easily interchange objects in NSMutableArray

Easily interchange objects in NSMutableArray

I have an NSMutableArray of UIViews that I put in UIScrollView which is
responsible for putting them in order. Right now I have this code for
changing two UIViews positions with each other:
UIView *viewToBeChanged = [views objectAtIndex:self.page];
UIView *previousView = [views objectAtIndex:previousPage];
[views removeObjectAtIndex:self.page];
[views removeObjectAtIndex:previousPage];
[views insertObject:viewToBeChanged atIndex:previousPage];
[views insertObject:previousView atIndex:self.page];
Is there a better way to change the position of an object in
NSMutableArray with another one? Thanks!

No comments:

Post a Comment