Arranging objects

Discussion in 'iOS Programming' started by ozzieing, Jan 18, 2010.

  1. ozzieing macrumors newbie

    Joined:
    Jun 24, 2009
    #1
    I have a group of objects (UIImageViews) in an array. I want to arrange them by yvalues. The greater the y value, the smaller the number in the array. So the one at the top of the page will be the first in the array and the one at the bottom is the last in the array. They move around so every second or so the array will have to be re-arranged.

    I have attempted to do this using NSSortDesciptors but the only way I can add a key to a UIImageView is to add .layer to the end but I can't add .layer to the array when I'm rearranging it so I get an error.

    Does anyone have any idea how I could do this? Any help would be greatly appreciated.

    Cheers,
    Ozzie
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You could subclass UIImageView or create a category method that returns this value. Something like:
    Code:
    - (CGFloat)yValue { return [self frame].origin.y; }
    Then use "yValue" as the sort key.
     
  3. ozzieing thread starter macrumors newbie

    Joined:
    Jun 24, 2009
    #3
    Thank you so much! Sorted and now my app will be done.
     

Share This Page