Scott
Scott

Reputation: 1222

How do you send messages to the window

I'm working on a challenge from a self-help book on Cocoa, here is where I'm stuck. I'm trying to resize the window from a single text field.

#import "DelegateAppDelegate.h"

@implementation DelegateAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
}

//some tip i don't understand from the challenge
-(NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;
{
    NSSize mySize = NSMakeSize(400, 200);
    NSLog(@"mySize is %f wide and %f tall", mySize.width, mySize.height);
    return mySize;
}

//button that will send the value from the text field
- (IBAction)userResize:(id)sender {

    NSInteger size = [_userSelectedSize intValue];
    NSSize userInputSize = NSMakeSize(size, (size/2)); 
    //there is only one text field named userInputSize. the size is halved
    //for the height

    NSLog(@"width = %f, height = %f", userInputSize.width, userInputSize.height);
    [_userSelectedSize setStringValue:@"updated"];

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~THIS IS WHAT I NEED HELP WITH
    [windowName setHeigth:userInputSize.heigth setWidth:userInputSize.width]
}
@end

I would prefer no information on the actual message to send, as I know these parameters are most likely wrong, but I would like to know where to find what to write for the window name.

Please note: The problem is that I don't know where to send the message.

FYI one of my files is named MainMenu.xib if that helps.

Upvotes: 0

Views: 100

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96323

I would prefer no information on the actual message to send, as I know these parameters are most likely wrong, but I would like to know where to find what to write for the window name.

Windows don't have names.

A window has a title, but that's displayed to the user—you can't use it to identify the window.

What you need is a way to connect the window in the nib to your code. You need some kind of receptacle in your code that you can plug your window into.

In a word: an outlet.

And you probably already have one. Xcode's non-document-based application template includes a window outlet in the application delegate, already connected by default. Look in your DelegateAppDelegate header to make sure.

So, you just need to address your setFrame:display: message to self.window.

Upvotes: 1

Related Questions