View Full Version : IBOutlets and IBActions, some working, some not

Feb 20, 2012, 12:20 AM
Hey guys, got a weird one here that I can't figure out. I've got a custom view XIB file, loading into the program using:

[NSBundle loadNibNamed:@"Basic" owner:self];

[window setContentView:basicView];

Now the view loads, and displays just fine. However, the problem occurs when fetching information from the display, or sending information to the display. Some of it works, some of it doesn't. For instance, in this section of code:

} else if (shapeButton.indexOfSelectedItem == 1) {
[dim1Label setStringValue:@"Width:"];
[dim2Label setHidden:YES];
[dim2Field setHidden:YES];

The program recognizes that shapeButton.indexOfSelectedItem does equal 1(or whatever the value is), but doesn't have any effect on the label and textField. I've checked my XIB file, and all the connections are there, but the code just isn't making the connections.

Anyone got any ideas what's wrong here?

Feb 20, 2012, 12:25 AM
Run your program. Set a breakpoint at the if. When the breakpoint is hit, are any or all of dim1Label, dim2Label, dim2Field null?

You can discover this using NSLog, too, but if you don't know how to use the debugger to set breakpoints and inspect variables, now's a good time to learn.

Feb 20, 2012, 06:15 PM
There are no nulls in any of the IBOutlets.

Feb 20, 2012, 07:12 PM
There are no nulls in any of the IBOutlets.

So how do you know that?

You're very sparse with details. Your code isn't working because you are doing _something_ wrong, and most likely it is some area in the code that you think is perfectly fine.

Feb 20, 2012, 07:45 PM
Yeah, I just figured out the problem. I've got 3 custom views, and they're swappable within the program. Some of the IBOutlets, like the three that I mentioned, exist in all 3 views. The problem I'm doing is in the applicationDidFinishLaunching where I load all 3 views from their XIB files, and thus the outlet in the code is only pointing at the last XIB loaded.

My plan at this point is to load only the currently active view, and release previous view from memory.