Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
I am following a book and it gives me this code:

Code:
-(IBAction)displayOrCloseWindow:(id)sender {
	//Fades in & out nicely
	if(isOpen) {
		[[self animator] setAlphaValue:0.0];
		isOpen = NO;
	}
	else {
		[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
		[self makeKeyAndOrderFront:self];
		[[self animator] setAlphaValue:1.0];
		isOpen = YES;
	}
}


It gives me an error when compiling it? Can anyone help?
 
What is the book? Be specific.


Post the code that defines the @interface for the class containing displayOrCloseWindow:.

If there isn't an isOpen instance variable, and there isn't one in a superclass, then you have the reason for the error: there is no variable named isOpen.

If the @interface does define an isOpen instance variable, make sure it's spelled exactly the same, including case.
 
The error is: 'isOpen' undeclared (first use in this function)

That explains it. The compiler tells you exactly what is wrong: You haven't declared "isOpen". Where did you think you declared it? Did you spell it wrong?
 
The interface didn't declare anything. Does anyone know how to make a window fade in and out with out this book? Thanks
 
The interface didn't declare anything. Does anyone know how to make a window fade in and out with out this book? Thanks

Well, you know how to fix it then. The sample code gives you the essential steps (most importantly use [self animator]), and you are supposed to fill out the rest. Could it be that your question is not really how to make a window fade in and out, but how to write a Cocoa application?
 
Whoops

Sorry about that I didn't see the part at the bottom telling my to add an instance variable. Sometimes I get so excited when I see the code I forget to read on:) It works now, thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.