开发者

Cocoa: Setting view in IB as hidden... cannot unhide it!

开发者 https://www.devze.com 2023-01-13 07:37 出处:网络
Using IB, I have dropped an NSView (menuView) inside another. I have set up my outlet and connected i开发者_C百科t to menuView.

Using IB, I have dropped an NSView (menuView) inside another.

I have set up my outlet and connected i开发者_C百科t to menuView.

I thought: " [self.menuView setHidden:NO] " would unhide it but it seems not to be working.

What else do I have to do?


Is the IB view object connected to the menuView variable? Otherwise modifying menuView will be a no-op. I would run it in the debugger and make sure menuView isn't null at the setHidden call. If it is, go back to IB and be sure to connect the view up to the outlet.


Have you verified that menuView is connected (NSLog() it before showing it), and that it's actually got some content?


Let's call the object with the connected outlet Fred.

You instantiated Fred in the nib, right?

And you have Fred loading the nib, right?

If the answer to either of those two questions was “no”, then disregard this answer.

If the answer to both of them was “yes”, then continue reading.

That's wrong. Fred should do only one of these two things. Chances are, you meant to make Fred the File's Owner, and hook up the connection there. The extra Fred you created in the nib is just that—an extra Fred, second to the Fred that loaded the nib. You have two Freds, and the one you have reporting the connection (in response to an action message, I'm guessing) is not the one whose outlet you connected to the menu view.

Kill off the Fred in the nib, leaving only the Fred that loads the nib. In the nib, declare the File's Owner as being of Fred's class, and in Fred's implementation, make sure that you are the File's Owner when you load the nib.

If you're using NSWindowController to load it, you need to pass yourself as owner explicitly; otherwise, the NSWindowController is the owner. Since you want Fred to be the owner, you need to tell the window controller that when you instantiate it. The alternative is to use NSBundle to load the nib directly, without an intervening window controller.


menuView.hidden = NO;

maybe?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号