• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating subviews programmatically ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating subviews programmatically ?


  • Subject: Re: Creating subviews programmatically ?
  • From: Vince Ackerman <email@hidden>
  • Date: Sun, 2 Dec 2007 04:35:03 -0800

NSView was screwing up the order of it's array of subviews.

If anyone else runs into this problem my solution that finally worked was to sort the subview array held by my NSView before calling setFrame. Apples docs do talk about sorting the subview array so I guess it's okay to do this, so I used:

[self sortSubviewsUsingFunction:intSort context: NULL];


and a function to compare an index I assigned each subview when init'd.

NSInteger intSort(id view1, id view2, void *context) // compare function to order subview array by gridnum
{
int v1 = [view1 gridNum];
int v2 = [view2 gridNum];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}


Fixed my problem though there is probably a performance hit having to do this for a large number of arrays.... I don't know.

Thanks for the help

Vince

On Dec 1, 2007, at 09:22, Dave Hersey wrote:


Well, by the descriptions you're showing, it looks like NSEnumerator is working correctly and you'll see the same thing from objectAtIndex. It must be something about how the subviews are dealt with by the system during resizing. There's no guarantee about the order in which subviews are drawn, and there may be no guarantee about the order they're kept in either. You're probably better off just creating an array of these view objects in the order you want at awakeFromNib or the like, and using that during the resize. That way you don't have to depend on the system maintaining your ordering.


- d

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Creating subviews programmatically ? (From: Vince Ackerman <email@hidden>)
 >Re: Creating subviews programmatically ? (From: Dave Hersey <email@hidden>)

  • Prev by Date: Re: How can I check to see if a mounted volume is an iPod or not?
  • Next by Date: change rect of tooltip in table view
  • Previous by thread: Re: Creating subviews programmatically ?
  • Next by thread: Re: Creating subviews programmatically ?
  • Index(es):
    • Date
    • Thread