Re: Making views disappear and reappear
Re: Making views disappear and reappear
- Subject: Re: Making views disappear and reappear
- From: "John C. Randolph" <email@hidden>
- Date: Sat, 23 Jun 2001 19:26:42 -0700
On Saturday, June 23, 2001, at 06:19 PM, Mark T wrote:
You do mean retain it *before* you remove it from the view hierarchy,
don' t you?
This is what I'm doing, and it still fails to reappear after
addSubview. Here's the code for the Hide/Show button's action, maybe
someone can figure out what I'm doing wrong:
- (IBAction)hideOrShow:(id)sender
{int i;
BOOL scrollViewDoesExist = NO;
NSScrollView * theScrollview = [self myScroll];
NSView * theSuperview = [theScrollview superview];
NSRect rectToRedraw = [theScrollview frame];
NSArray * tempArray = [[sender superview] subviews];
for(i = 0; i<[tempArray count] ; i++)
if([tempArray objectAtIndex:i] == [self myScroll]);
scrollViewDoesExist = YES;
Okay, the first thing that jumped out at me is that you can replace this
for loop with:
if ([[sender superview] subviews] indexOfObject:[self myScroll]] !=
NSNotFound)
scrollViewDoesExist = YES;
Also, for future reference, it's better to use NSEnumerators than for()
loops to iterate over an array.
if(scrollViewDoesExist)
{ [sender setTitle:@"Show"];
[theScrollview retain];
[theScrollview removeFromSuperview];
[theSuperview setNeedsDisplayInRect:rectToRedraw];
What happens if you change the line above to just [theSuperview
display] ?
You might want to check the retain count of theScrollview and also see
what the frame of the theScrollView is after you re-insert it into the
view heirarchy. It may be lying outside the bounds of its superview.
-jcr
"These kids today don't know the simple joy of saving four bytes of
page-0 memory on a 6502" - unknown