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
Hello,
I am having some issues with the mouseDown method.

Here is my code:

Code:
-(void)mouseDown:(NSEvent *)theEvent{

    [window setTitle:@"News Tiles"];
    [window setContentView:tileView];
  


}
This code is inside WelcomeView.h (Subclass of NSView). window is an IBOutlet NSWindow and tileView is an IBOutlet NSView.
Why won't the window's tile change and why won't the view change. I get no errors or warnings the code just doesn't work. I put an NSLog inside the mouseDown: method to see if WelcomeView was taking any clicks and it was. The NSLog worked, but the setTitle and setContentView don't
Any Ideas?
Thanks!
 
I'm not sure what you mean by 'nil'
I declare the window like so...
Code:
IBOutlet NSWindow *window;
 
I'm not sure what you mean by 'nil'
I declare the window like so...
Code:
IBOutlet NSWindow *window;

nil = a pointer variable that's not pointing to any object.

Insert the following code at the top of the method and tell us what it prints:
Code:
NSLog(@"window=%@", window);
 
It looks like 'window' isn't connected in the nib. Double-check your connections.
 
It is connected. It is connected to the AppDelegate AND to a WelcomeView. So can you have it connected to 2 .h files. Can you not do that?
 
It is connected. It is connected to the AppDelegate AND to a WelcomeView. So can you have it connected to 2 .h files. Can you not do that?

You can have an object connected to as many outlets as your want. What you can't do is try to connect multiple objects to a single outlet.

Try adding the following code to your WelcomeView:
Code:
- (void)setWindow:(NSWindow *)aWindow
{
  NSLog(@"%s self=%@ aWindow=%@", __PRETTY_FUNCTION__, self, aWindow);
  window = aWindow;
}

And then put the following to code at the top of mouseDown.
Code:
  NSLog(@"%s self=%@ window=%@", __PRETTY_FUNCTION__, self, window);

What I'm looking for is a) is the window being set, and b) is the window being set in the same instance of WelcomeView as is being called by mouseDown. So I'd hope to see 2 log messages, both with the same self and window.
 
The following is outputted:


-[WelcomeView mouseDown:] self=<WelcomeView: 0x100536eb0> window=(null)
 
What does this output:

Code:
NSLog( @"%@", [self window] );

when you put it in one of those methods?
 
@Sydde The following gets printed out:
2011-05-24 18:13:56.853 News Tiles[4265:60b] <NSWindow: 0x1005291a0>
 
@Sydde The following gets printed out:
2011-05-24 18:13:56.853 News Tiles[4265:60b] <NSWindow: 0x1005291a0>

Is that the window that contains your view, or are you concerned about a different window? Because a view almost always knows what window it is in. Would using the -window method be good enough?
 
Is that the window that contains your view, or are you concerned about a different window? Because a view almost always knows what window it is in. Would using the -window method be good enough?

Great suggestion.


@Blakeasd Go with Sydde's suggestion.

If this is a different window, then you should name your ivar something different so to avoid any potential confusion with window as inherited from NSView.

But that doesn't explain why you didn't get a log message from setWindow. There is something wrong with your NIB connection between the window and the view.
 
Thanks @Sydde and @jiminaus. I used the views -window method and it worked.
Here is my fixed code if anyone has a similar problem:
This is in my mouseDown: method inside the WelcomeView
Code:
 [ [self window] setTitle:@"News Tiles"];
 [ [self window]setContentView:tileView];
Thanks Again!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.