I want to change the order of subviews on a view and found the method sortSubviewsUsingFunction:context and found out how to use it.
the problem is that whenever i call it, the subviews keep flipping order.
so, subview1 which should be behind subview2 will become in front and then when the method is called again they'll switch so that subview1 is behind subview 2
i'm calling the method similar to this:
and the comparison method is like so:
why does it reorder things differently each time?
as far as i can tell it's quite the same as what you see in this thread here: http://www.cocoabuilder.com/archive/cocoa/119585-sortsubviewsusingfunction-question.html
the problem is that whenever i call it, the subviews keep flipping order.
so, subview1 which should be behind subview2 will become in front and then when the method is called again they'll switch so that subview1 is behind subview 2
i'm calling the method similar to this:
Code:
- (IBOutlet)reorderSubViews:(id)sender {
[baseFocusView sortSubviewsUsingFunction:(NSComparisonResult (*)(id, id, void*))compareViewDepth context:NULL];
}
Code:
int compareViewDepth(id firstView, id secondView, void *context)
{
SpecialView *first = (SpecialView*)firstView;
SpecialView *second = (SpecialView*)secondView;
if([first.controller.z intValue] == [second.controller.z intValue]) {
return NSOrderedSame;
}
if([first.controller.z intValue] < [second.controller.z intValue]) {
return NSOrderedAscending;
}
return NSOrderedDescending;
}
why does it reorder things differently each time?
as far as i can tell it's quite the same as what you see in this thread here: http://www.cocoabuilder.com/archive/cocoa/119585-sortsubviewsusingfunction-question.html