• 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: NSView setVisible: method -- NOT
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSView setVisible: method -- NOT


  • Subject: Re: NSView setVisible: method -- NOT
  • From: Jeffrey Mattox <email@hidden>
  • Date: Mon, 7 Apr 2003 22:31:31 -0500

After considering the various replies (thanks), I solved my problem as described below.

To clarify, I want to turn the visibility of several text fields on and off both in Cocoa and in AppleScript. The scheme AppleScript uses, removing the view from the super view, is too complicated to mimic in Cocoa (and remain in sync with changes made in AS), and the issue of resizing the window when such a field is "invisible" is a snake pit.

My solution was to write a method in Cocoa that sets the text color to clear (for invisible) or black (for visible), and call that routine in both AS and Cocoa. To wit:

In AS:

call method "setTextField:visible:" with parameters {myTextField, false}

In Cocoa:

[NSApp setTextField:myTextField visible:NO];

Implementation:

-(void)setTextField:(NSTextField *)theTextField visible:(BOOL)visibleFlag
{
if ( visibleFlag ) {
[theTextField setTextColor:[NSColor blackColor]]; // make visible
} else {
[theTextField setTextColor:[NSColor clearColor]]; // make invisible
}
}

The text fields I am operating on are boarderless (IB: "System Font Text"), so this works. If the text fields have boarders or other attributes such as a background color, it would be necessary to change those attributes to make the field invisible, and then change them back later. To make it general purpose, a dictionary could be used to save those original settings when the field is made invisible and then restore them when the field is made visible.

Jeff


At 12:19 PM -0600 3/31/03, Brian Webster wrote:
Yes, presumably the framework must be storing the "invisible" views somewhere. When you call removeFromSuperview, it removes the view from the hierarchy period, and the superview will release the view, so if the view is not retained before that, it will be deallocated upon removal.

One problem with this method of adding/removing views is that if the window is resized while the view is not in the view hierarchy, then when you add the view back in, it will be placed in its old location and will not have an updated frame based on the resizing of the window that occurred.

On Monday, March 31, 2003, at 12:01 PM, Jeffrey Mattox wrote:

In Cocoa, then, if I have a view that has been made invisible by AppleScript, how do I set it back to visible? I assume AS saves the superview somewhere. Do I have to do the same earlier, when the view is still visible? The superview will usually be the view of the main window, but couldn't it also be the view of a box or tab, etc.?

Jeff

At 9:29 AM -0600 3/31/03, Brian Webster wrote:
On Sunday, March 30, 2003, at 11:24 PM, email@hidden wrote:

How come AppleScript has a "visible" property for a view that can be
set true/false, but there are no setVisible:(BOOL)flag or isVisible
methods in Cocoa for NSView?

The isVisible and setIsVisible methods are implemented in the AppleScriptKit framework as a category on NSView. This is revealed by class-dump, since of course the ASK framework has no header files. The implementation of these methods simply adds and removes the view in question from its superview. This can be seen by setting the visible flag of a view to false and then trying to access its window property, which will then return a missing value, indicating that the view is no longer contained in any window.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: NSData to long
  • Next by Date: How-To: private framework
  • Previous by thread: Re: NSData to long
  • Next by thread: How-To: private framework
  • Index(es):
    • Date
    • Thread