Can't create outlet using Interface Builder - Lock symbol shown - iphone

I'm trying to create outlets using the Interface Builder, however when drag the UILabel from the IB to my controller's .h file the big lock symbol flashes for a few seconds and it doesn't actually create the bind between the UILabel and the outlet (although the code is generated). I also noticed an empty circle is created by this new definition. When it worked, a filled in circle was created on the side).
I've checked the UILabel and all parent views and have checked that their "Lock" property is set to "Inherit (Nothing)" (and have even set them all to "Nothing").
In the IB the UILabel doesn't show the "x" that appear when a UILabel is locked either.
So I have no idea if I'm missing to unlock something, or what I'm doing wrong to be able to create this outlet.
I don't know if this is relevant, but I'm using a custom view controller, and I'm using this same view controller subclass for 2 different view controllers in the same storyboard. I had no problems creating outlets this way for the first view controller.
Tryed reopening XCode (using 4.4.1) with no luck.
Any help is appreciated!

So are you dragging both UILabels from each View Controller into the same file? I don't think that this is possible, on the second view controller, try to Ctrl drag to the file owner within the IB view, that is, assuming that both views are connected to the same instance.
Also, in your identity tab in storyboard, under Localization Locked, make sure your storyboard locked setting is set to default as mentioned in https://stackoverflow.com/a/11169636/720175

I tried adding a totally new scene and would also get the lock symbol. So it wasn't only the scenes, but the whole storyboard. So a quick search on SO lead me to the answer:
https://stackoverflow.com/a/11169636/720175

Related

Why am I not seeing objects that I'm adding to my storyboard in my ViewController.swift file?

I'm new to Xcode and I'm having a hard time understanding the platform. I would like to know why whenever I'm adding objects (buttons, labels, image views, etc.) to my storyboard, I don't see any change in my .swift file connected to its view controller.
If someone could explain it to me precisely it would be much appreciated.
Because there shouldn't be any in the first place. Connections between the Interface Builder (IB) and your code must be placed by hand (either by writing them first and connecting by ctrl-dragging to the function, or letting xCode generate them by ctrl-dragging them into place).
If you need to reference any views you have in interface builder from your code, make sure that:
IB knows the class the view belongs to (set this in the Identity Inspector to the right for the main container view, usually the UIViewController)
There is a corresponding #IBOutlet (or #IBAction) marked property (or function)
Then just ctrl-drag from the object in IB to the property in the code, and everything should run smoothly.
Here's some info if you need more help connecting the views in the IB to your code.
Happy coding!

Cannot get button to call controller code iPhone 4

My View has a button, myButton, in my XIB. In the XIB the File's Owner is of class HelloWorldViewController. And the view for File's Owner is my View in the XIB.
In the HelloWorldViewController(which resides in MainWindow.XIB) I have - (IBAction) doMyButton:(id)sender and I have the corresponding definition in the HelloWorldViewController.h file.
For my View I have Events (again in the XIB) Touch Up Inside --> File's Owner doMyButton.
For File's Owner I have Received Actions doMyButton --> Rounded Rect Button Touch Up Inside.
I have a debug point on the first line of code that is inside the 'doMyButton' method. When I touch the button (with my mouse in the simulator) I do not hit my break point.
WTF?
Screen Captures of IB if it helps:
Overview
Properties Of Button
If every thing is fine then you are not setting the break point i.e. you are running your code using cmd+R use cmd+y or cmd+enter. cmd+r will run without considering your break points.
Do any of your IBOutlet items function?
If they don't (and since you renamed your XIB file), be sure the File's Owner has the correct custom class set in the interface builder. Otherwise it could be calling the wrong class which could be why your break point isn't firing.
Note: This is unlikely as such an issue should cause a build problem, but I've seen stranger things happen.
Thanks to a co-worker I found out what the problem was. The view I had with the button was in my HelloWorldViewController.xib as it is supposed to be. However, I had drug that view into the Main.xib to be the primary view for the NavController I had setup. I was editing the view in the HelloWorldViewController.xib when I should have been editing (read: making the connections) in the Main.xib where the view was duplicated for the NavController.
I assumed that NavController was simply pointing to the other XIB where my original view was defined, not running off a copy of it. Kind of messed up for a newb perspective.

How to make a "view" Outlet show up in a ViewController nib?

I'm working on my first iPhone app and have been able to get most things done. There's one problem that I've run into a few times and I want to understand the issue better.
In XCode, if I go File->New File->UIViewController subclass and make sure that both UITableViewController subclass and With XIB for user interface are checked, then it creates a MyViewController.h, MyViewController.m, and MyViewController.xib.
When I look at this xib in Interface Builder, you can see that the File Owner has an Outlet called view that is already connected to the UITableView. No problem. This all makes sense and is great.
My issue comes when I've changed the type of my class (or done something else) and some how the "view" Outlet goes away. I get an error saying "view not showing up in file owner outlet".
My question is how do I then reconnect the UITableView as the "view" of the ViewController when the Outlet goes away? The only way I've been able to get it to work is to literally start over with a new xib/viewcontroller.
That "view" outlet should be coming from the parent class (in your case UITableViewController).
What do you mean by change type? If you are changing the name of your class, try using Edit > Refactor with the class name selected in Xcode.
In the "Document" window (cmnd + 0) - control + click on file's owner, a weird looking line thing will show up. drag the mouse over to your view and release. a little drop down will come up from which you can set the view to the File's Owner View outlet.
Typically the "view" outlet would be coming from the parent class (UITableViewController). If it's not showing up, then Interface Builder is not connected to your project than this could happen instead.
My problem was due to an edge case as described here: Interface Builder and Xcode integration not working

Multiple Xib files - Same Class

I'm fairly new at this, but I think what I'm looking to do makes sense. I have a xib that is displayed in portrait and one that is displayed in landscape. Both views are similar, but have a few differences. Some of the buttons, labels and textfields are the same.
I can reveal one and hide the other when the orientation is changed - that's not the problem.
Basically I'm looking to have one place where I can handle all of the common button click responses or text changes. When a user is in portrait mode and enters text or selects a button, then they change to landscape mode the corresponding buttons and text will be updated.
I tried adding an NSObject in interface builder and assigning it to a new class that has outlets and actions for the buttons and textfields, but when I interact with a button I get an "unrecognized selector sent to instance" error in xcode.
Any help would be great.
Best,
Ward
Objects you add in Interface Builder are instantiated when the XIB loads, you cannot have the same object in multiple XIBs.
What you use to connect multiple XIBs is the "File's Owner" object you see in each XIB. When you load a XIB using [NSBundle loadNibNamed:#"myXIB" owner:self] then what you pass in as owner object is ending up as the File's Owner in the loaded XIB and Cocoa will connect the IBOutlets and IBActions you have in it (be sure to set the proper class of the File's Owner object in Interface Builder).
So then you could make the controller object of your landscape view the owner of the portrait view XIB and put all IBActions in that controller, where they will be accessible from both XIBs (through the controller in one and through the File's Owner in the other).
Don't forget that xibs aren't templates — they are freeze-dried objects. A button in one has no connection to a button in the other.

Using default tab-controller created project... first view controller doesn't respond to addsubview

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 would love to hear what you guys think about this problem and how to solve it.
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.
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.