Re: How can modal window pass messages to its parent window?
Re: How can modal window pass messages to its parent window?
- Subject: Re: How can modal window pass messages to its parent window?
- From: Seth Willits <email@hidden>
- Date: Mon, 18 Mar 2013 13:38:13 -0700
On Mar 18, 2013, at 12:15 PM, Chris Tracewell wrote:
> I have a main window which has a child/auxilary window. When the user presses a button in the UI the main window controller inits the child, assigns itself as the object for the child window's myOwner property and then launches the child window as a modal via NSApp runModalForWindow. This worked fine in XCode 3 but now I'm finally making the leap to XCode 4.6 and converting to ARC and it does not like this semantic because it does not know what class myOwner is when I make method calls to it and thus gives me warnings all over the place. I can't really include the parent header in the child window controller as it is included in the parent window controller. How should I be doing this?
>
> myProductBuilderWindow = [[TKProductBuilderWindowController alloc] initWithWindowNibName:@"ProductBuilder"];
> [myProductBuilderWindow setMyOwner:self];
> [NSApp runModalForWindow:[myProductBuilderWindow window]];
>
> Basically the main window controller has several properties, mostly arrays, that the child window needs access to to do its specialized work.
You didn't post what these 'warnings all over the place' are, but it this very much sounds to me like it has nothing to do with modal windows or Xcode versions, but by however you've declared your "MyOwner" property. It sounds like you declared it as an "id" and never imported the header into *the .m* file of your builder window controller.
The general pattern for any time one class has to use another:
-- Foo.h --
@class Bar;
@interface Foo : NSObject
@property Bar * bar;
@end
-- Foo.m --
#import "Foo.h"
#import "Bar.h"
@implementation Foo
@end
Forward declare in the .h, #import in the .m
With your parent/child case assuming Parent has a Child property and Child has a Parent property:
-- Child.h --
@class Parent;
@interface Child : NSObject
@property Parent * parent;
@end
-- Child.m --
#import "Child.h"
#import "Parent.h"
@implementation Child
@end
-- Parent.h --
@class Child;
@interface Parent : NSObject
@property Child * child;
@end
-- Parent.m --
#import "Parent.h"
#import "Child.h"
@implementation Parent
@end
(Naturally Child's 'parent' property should be a weak reference and Parent's 'child' strong…)
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden