0
votes

I'm trying to initialize the values inside a view (created inside a nib file) programmatically. I'll try to do a little briefing of my scenario:

I've got a nib file, with a view inside. This view has some items (TextViews, CheckBox, etc)

This view is pretended to be a template of the inclusion of new data to my program (it's not the main view). Here is the view's windows initialization:

NewWindow = [[NSWindow alloc] initWithContentRect:frame
                                        styleMask:( NSBorderlessWindowMask| NSClosableWindowMask | NSTitledWindowMask) 
                                          backing:NSBackingStoreBuffered
                                            defer:NO];
[NewWindow setIsVisible:NO];
[NewWindow setReleasedWhenClosed:NO];
[NewWindow setBackgroundColor:[NSColor windowBackgroundColor]];
[NewWindow setContentView: MyView];
[NewWindow setDelegate:self];

I call the windows making it visible.

MyView is a IBOutlet connect to the nib's view. This view is a modified NSView, and it got it's own class file.

Everything on the view (IBOutlets) is connected and working properly (I know because when, for example, I click a button, the action related to it work just fine).

I created a initialization method on MyViews class, to initialize the template's fields according to my needs. I call the initialize like this:

[MyView initialize:InitClass];

My problem I'm facing is, this MyView object is not the same as the one inside the nib file, even with all connections (IBOutlets) connected. Then, when I run this method, nothing happens (as the initialize method is trying to change the value of unallocated fields).

I have included some NSLog to see my objects address, and confirmed that the one on the nib file is not the same as the one on the IBOutlet

I'm creating this IBOutlet property like this:

@property (assign) IBOutlet MyNewView *MyView;

Does anyone knows how to solve this problem?

1

1 Answers

1
votes
  1. You should never call viewWillMoveToWindow:. It's an information lifetime event.

  2. It doesn't seem like you're showing enough code. I don't see any evidence that you're loading the nib. Naturally if you instantiate the MyView by calling [[MyView alloc] init] or similar, that's a different MyView. If you want your outlet to point to the one in the nib you need to load the nib with yourself as owner.