• 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: Problem moving subview within superview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem moving subview within superview


  • Subject: Re: Problem moving subview within superview
  • From: Stephane Sudre <email@hidden>
  • Date: Fri, 10 Feb 2006 18:15:55 +0100


On 10 févr. 06, at 18:01, Ivan Kourtev wrote:

Hello,

I have a simple app with window and a button in it. I want to programmatically change the appearance of the button and its position within the window. I used exactly the following code:

[button setButtonType:NSMomentaryPushInButton];
[button setBezelStyle:NSRecessedBezelStyle];
[button setImage:bImage];
[button setFrame:NSMakeRect(0,0,35,35)];
NSView *contentView = [window contentView];
[button retain];
[button removeFromSuperview];
[contentView addSubview:button];
[button release];
[button setNeedsDisplay:YES];
[window displayIfNeeded];

but there is a problem with "erasing" the button from its old position within the window. The button shows up at its new location with its new attributes exactly as I want but old button picture remains in the window. The only way to make it go away was to hide window/app and unhide.

Also, I was able to make it work programmatically by changing the last line to [window display].

Why is this happening? Shouldn't -displayIfNeeded have worked? In the docs, Apple actually advises against using -display and sticking with -displayIfNeeded.

Also, is that the right way to do what I was trying to? I couldn't think of anything more elegant but I'd love to hear if there is a better approach.

I would do it that way:

NSView * buttonSuperView = [button superview];

// We probably don't want the frame to change before we remove it from the view hierarchy

[button retain];
[button removeFromSuperview];

[button setButtonType:NSMomentaryPushInButton];
[button setBezelStyle:NSRecessedBezelStyle];
[button setImage:bImage];
[button setFrame:NSMakeRect(0,0,35,35)];

[buttonSuperView addSubview:button]; // Maybe you should set the frame origin
[button release];


since it's working OK on my machine.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Problem moving subview within superview
      • From: Ivan Kourtev <email@hidden>
References: 
 >Problem moving subview within superview (From: Ivan Kourtev <email@hidden>)

  • Prev by Date: Re: Drawing NSAttributedString with negative leading/spacing?
  • Next by Date: Re: Problem moving subview within superview
  • Previous by thread: Problem moving subview within superview
  • Next by thread: Re: Problem moving subview within superview
  • Index(es):
    • Date
    • Thread