Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

creating a window delegate - Hillegass chapter 6

 
   Mac (Home) -> Programmer Help RSS
Next:  Add to Party Shuffle  
Author Message
superavit

External


Since: Aug 10, 2008
Posts: 1



(Msg. 1) Posted: Sun Aug 10, 2008 6:21 pm
Post subject: creating a window delegate - Hillegass chapter 6
Archived from groups: comp>sys>mac>programmer>help (more info?)

Guys/Gals,
I am trying to complete the challenge in Hillegas book, chapter 6. I
need to create a delegate to a window that constraints its resinzing.
I have the following code:
// AppController.h
// Delegate Try
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject
{
IBOutlet NSWindow *myWindow;
}

- (NSSize)windowWillResize:(NSWindow *)sender
toSize:(NSSize)proposedFrameSize;
@end
// AppController.m
// Delegate Try
#import "AppController.h"
@implementation AppController
- (id)init
{
[super init];
myWindow = [[NSWindow alloc] init];
[myWindow setDelegate:self];
return self;
}
- (NSSize)windowWillResize:(NSWindow *)sender
toSize:(NSSize)proposedFrameSize
{
proposedFrameSize.height = (proposedFrameSize.width*2);
NSLog(@"myWindow will resize to %f wide and %f tall",
proposedFrameSize.width, proposedFrameSize.height);
return proposedFrameSize;
}
- (void) dealloc
{
[myWindow release];
[super dealloc];
}
@end
I connected the Appcontroller as a delegate of the window and the
window as an outlet of the Appcontroller. But as the application
starts and resizes, nothing happens along the lines of
constraining...
Help this newbie! Please
Jason
Back to top
Login to vote
Gregory Weston

External


Since: Jun 06, 2005
Posts: 660



(Msg. 2) Posted: Mon Aug 11, 2008 7:55 am
Post subject: Re: creating a window delegate - Hillegass chapter 6 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article
<933bf1aa-5d71-464b-9d59-5a4f79d36439 DeleteThis @k37g2000hsf.googlegroups.com>,
superavit <jasonkrac DeleteThis @gmail.com> wrote:

> Guys/Gals,
> I am trying to complete the challenge in Hillegas book, chapter 6. I
> need to create a delegate to a window that constraints its resinzing.
> I have the following code:
> // AppController.h
> // Delegate Try
> #import <Cocoa/Cocoa.h>
> @interface AppController : NSObject
> {
> IBOutlet NSWindow *myWindow;
> }
>
> - (NSSize)windowWillResize:(NSWindow *)sender
> toSize:(NSSize)proposedFrameSize;
> @end
> // AppController.m
> // Delegate Try
> #import "AppController.h"
> @implementation AppController
> - (id)init
> {
> [super init];
> myWindow = [[NSWindow alloc] init];
> [myWindow setDelegate:self];
> return self;
> }
> - (NSSize)windowWillResize:(NSWindow *)sender
> toSize:(NSSize)proposedFrameSize
> {
> proposedFrameSize.height = (proposedFrameSize.width*2);
> NSLog(@"myWindow will resize to %f wide and %f tall",
> proposedFrameSize.width, proposedFrameSize.height);
> return proposedFrameSize;
> }
> - (void) dealloc
> {
> [myWindow release];
> [super dealloc];
> }
> @end
> I connected the Appcontroller as a delegate of the window and the
> window as an outlet of the Appcontroller. But as the application
> starts and resizes, nothing happens along the lines of
> constraining...
> Help this newbie! Please
> Jason

Something you're not showing us is going wrong, because this works as
you intend here.

Some notes:

1. When the app launches, AppController>>init will be invoked. That will
blow away any value you've established for the myWindow outlet in the
nib. However the app controller will still be the delegate for the nib
window as long as you actually did establish that relationship. If
you're *not* setting the controller as the delegate of the window in the
nib, the code above isn't going to work as you expect. The window
on-screen is the one from the nib. The window you create in your init
method never gets shown. As it's presented, your init and dealloc
methods are not having a meaningful effect on the operation of your
program.

2. As noted previously, you really should get into the habit of caring
about the return value from the superclass' initializer. It doesn't
strictly matter here, but consistency is easier to debug and reinforces
the habit for when it does matter.

--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Creating text image in code - What's the easiest (i.e least amount of code) way to generate an NSImage with black text on a transparent background? It needs to be done in code, as the text will be constantly changing. (The last time I did any 2D graphics programming was in QuickDraw...

Creating a Virtual Audio Driver? - Hi, Just wondering if anyone has any thoughts or experience on creating what I think you would call a "virtual" audio driver for OS X? I want to create an audio driver that goes between a standard application (outputting standard wave audio...

NSView: clipping when creating PDF? - I'm having troubles using dataWithPDFInsideRect to generate a PDF of an NSView which contains other views. The inside views do lots of NSBezierPath drawing, and rely on clipping to keep the drawing inside the views. This works fine for drawing to the....

Creating folders - a Windows Programmer Question - OK, I've been beating my head on this for a couple of days. Here's my question: In Windows if I want to create a directory path, I can recursively call a create directory function and build each part of the path using mkdir() or CreateDirectory(). ...

window server - Hi How can i know , is my application using windowserver ? My application is using IOkit and runloop concept. I put it in startupitems. it execute successfully on 10.4 but on 10.5 following thing happen ->warning - 3891612 , untrusted application a...
       Mac (Home) -> Programmer Help All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
 Linux Forums
  Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact