views:

935

answers:

2

I created a project using the default tab-controller project. I am using interface builder to edit the .xib file and add images and buttons. I hook them up to the FirstViewController object in interface builder (that I created and set it's class to the same as the code file). I hooked everything up using IBoutlets and IbActions.

Everything was working fine, but then I made some changes in interface builder (added a UILabel) and now a method that is run when clicked (I ran through it with the debugger) has a line that adds a subview to the view controller... and it acts as if it wasn't executed. The method (and code is run through) is executed with no errors (per the debugger) but the view is simply not being added. This happened after I made some change via interface builder.

Now, if I hook-up my button to "Selected First View Controller" by clicking on the appropriate tab and dragging the IBOutlet to the UILabel, that label now has multiple referencing outlets. Now, if I do the same thing for the button, the method (the IBAction) is executed twice but the subview is actually added and displayed. But, I get a memory access error because my IBAction (button) method access a property that stores something. I am guessing this has to do with somehow creating the memory in the First View Controller but trying to access it in the Selected First View Controller? ... If that makes any sense?

I have no idea why this is happening and why it just the button suddenly stopped working. I tried to explain this problem the best I could, it is sort of confusing. But if anyone has any tips or ideas I'd love to hear what you guys think about this problem and how to solve it.

+1  A: 

Are you sure the first outlet is actually hooked up. If you name an outlet such that it conflicts with some other property that is set while the nib is loading (via initWithCoder:) it can cause things to not end up being hooked up properly. You can check that by NSLog'ing out the value of the outlets in your awakeFromNib.

Louis Gerbarg
+1  A: 

It also sounds - and feel free to correct me if I'm mistaken - that you're attaching actions in the view loaded by the tab bar to the tab bar's controller. The two entities are quite different and any data that you wish to access from the view should be referenced from the view's controller rather than the tab bar's controller (which should have a fairly light-weight job in loading and unloading your other view controllers). Similarly, you should not be adding a subview to the view controller, it has no idea about what to do with a subview - you should be using the view controller to add a subview to your view. While it seems like a matter of semantics a view controller is fundamentally different from a view. The former has the job of managing the contents and behaviors of a view and to respond to the view's actions where necessarily while the latter is simply a mechanism for displaying thing son the screen.

wisequark