Using the default built-in tab controller ... first look controller not responding to addubview

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

and IBActions

.

Everything worked fine, but then I made some changes to the interface constructor (added UILabel

) and now the method that fires on click (I skipped it with the debugger) has a line that adds the subview to the view controller and it acts like as if it hadn't been done. The method (and the code runs) runs without error (for the debugger), but the view just isn't added. This happened after I made some changes through the interface builder.

Now if I connect my button to the "Selected First View Controller" by clicking the appropriate tab and dragging IBOutlet

to UILabel

, this label now has multiple reference points. Now if I do the same for a button, the ( IBAction

) method is executed twice, but the subview is actually added and displayed. But, I get a memory access error because my method IBAction

(button) is accessing a property that is holding something. I'm guessing it has something to do with creating memory in the First View Controller in some way, but trying to access it in the Selected First View controller? If it makes sense?

I have no idea why this is happening or exactly why the button suddenly stopped working. I have tried to explain this problem as best I can, but this is somewhat confusing. But if anyone has any advice or ideas, I'd love to hear what you guys think about this issue and how to fix it.

0


source to share


2 answers


Are you sure the first outlet is actually plugged in. If you name the socket such that it conflicts with some other property that is set when nib loads (via initWithCoder :) it can cause things to not wiring properly. You can check that NSLog is outputting the output value in your awakeFromNib.



+1


source


It also sounds like - and feel free to correct me if I'm wrong - that you are adding actions to the view loaded by the tab bar in the tab bar controller. The two objects are completely different, and any data you want to access from the view must reference the view controller, not the tab bar controller (which should have a fairly easy job of loading and unloading your other view controllers). Likewise, you shouldn't add a subview to the view controller, it has no idea what to do with the subview - you must use the view controller to add the subview to your view. While this sounds like a semantics question, a view controller is fundamentally different from a view.The former has the task of controlling the content and behavior of the view and reacting to the actions of the view where necessary, while the latter is simply a mechanism for displaying the thing played on the screen.



+1


source







All Articles