Is there any way to find which UI element an IBOutlet declared in code is connected to?
Go to your view controller file where you have declared IBOutlet (.h or .m). Then you can see left side of each variable declaration there is a dark grey round image. (It is filled if you have connected that IBOutlet with Storyboard/Xib unless it is unfilled.)
By clicking that image you can see small popover which shows connection of outlet. See below image will show you.
You can search for the IBOutlet property name in the project directory.
There you will find the corresponding xib file and UI element.
Related
In my project, I want to display a popup and the view of this popup is defined in a .xib file.
To do that I use this line of code :
myPopupView = NSBundle.mainBundle().loadNibNamed("NibView", owner: self, options: nil)[0] as! UIView
Until then, it works. But the problem is when I try to add an IBOutlet. My Xib file is connected to a uiviewcollection, and I manage to create an IBOutlet on the Textfield I have in the xib file. But when now I run again my app, I have this famous message :
this class is not key value coding-compliant for the key...
So if I look on Internet, everybody says to delete the IBOutlet by clicking on the cross button in Inspector, BUT I don't want to delete it because I need this IBOutlet. So isn't it possible to have IBOutlet in a xib file ?
Thanks :)
This is very common error which means the IBOutlet you have taken in .xib is not connected to the relevant class. This kind of error I experience when i have taken a outlet and given some name like lblUserName but later i renamed that to lblFriendName, then the label in xib is still connected to lblUserName as well as lblFriendName, so at the time of compilation the xib did not find the connection for lblUserName and throws error.
So go to your xib, right click on the outlet in the xib, then you will see the cross button to disconnect. So disconnect it and connect it again.
During that also you can see the connection name, it must be wrong name or there would be two connection foe the same label in which one would be correct and another must be wrong (This case when you rename a connection as i explained)
Hope you understand, and it helps...
Happy coding ...
Can someone please tell me what are the steps in InterfaceBuilder to connect a set of UITextView objects to an IBOutletCollection? In my XIB file (say myfile.xib) I have a row of 8 UITextView objects. In my myfile.h file I declare an IBOutletCollection:
#property (nonatomic, retain) IBOutletCollection(UITextView) NSArray *textViews;
Now I want to connect the XIB UITextView objects to the IBOutletCollection. I tried to CTRL drag from the first UITextView in the XIB to FileOwner, but that didn't show me any IBOutlets. I tried to CTRL click (right click) on FileOwner and that popped up some little black menu. That showed my textViews outlet collection, so I tried dragging from the little circle by textViews to my UITextView objects in the XIB, but that didn't do anything. I searched google to find some sort of info on this, but I only found statements like "connect your UITextView to the IBOutletCollection in the usual way." I don't know what "the usual way" is. Please help.
Are you sure you were were dragging from the correct "little circle" to your text views, because that works fine for me.
Another way is to do it just like you connect an outlet by opening the assistant editor so you can see both the xib file and the controller's .h or .m file. Starting with no code in the controller, select the text view and control-drag from it to the area under #interface, and it should say, "Insert Outlet or Outlet Collection". When you let go, fill in the name, and then change the "connection" pull-down from "outlet" to "outlet collection". After the first one is done, control-drag from the other text views to that line of code.
Make sure the class of File's Owner is set to the class you are trying to hook up the outlet collection to. Open the Identity Inspector (Ctrl + Cmd + 3) and type the name of your class in the box. Then try hooking the outlets up again.
I am trying trying to copy all of the functionality of this example app provided by Apple called AVCam: https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112-Intro-DontLinkElementID_2
I am 99% done with copying this code, but I just have one final problem. I have an IBOutlet statement that looks like this: #property (nonatomic, weak) IBOutlet MediaCapturePreviewView *previewView;
According to the Apple sample code, this outlet is supposed to be connected to a View object that has been placed on top of the normal/default view.
Here is a screenshot of what the Connections Inspector looks like in the Apple example:
You will notice that the IBOutlet called "previewView" has been connected to something called the "Cam Preview View".
Also, in this screenshot, you can see that I am able to select this View object by itself and that it shows a Referencing Outlet in it's connections inspector for the same IBOutlet and View Object:
My problem is that I cannot get the IBOutlet code to connect to this View Object. I have tried the normal behavior of clicking and dragging to make the connections but it just wants to create a new outlet. It will not let me connect to the outlet that I have already created.
I have been playing with this for 2 hours now and just can't get it to work like Apple's sample code.
Any help is greatly appreciated thank you.
In your .xib file, make sure that UIView class is assigned as AVCamPreviewView instead of UIView.
A few possible solutions:
Save the file with the IBOutlet you're trying to connect up (the source code, not the IB)
Clean, rebuild
Restart Xcode.
I am following a tutorial HERE on creating a table-view controller in Xcode. I am using the latest version of Xcode (Xcode 5). At the top of the tutorial it says its for iOS 5.
In the tutorial a cell is created and an UIImage and a few labels are dragged onto the cell. It goes on to say to Ctrl-Click the white space of the cell and then drag to the labels and image to establish the outlet connection. See screen grab from tutorial.
When I do this, I dont get the same options as per the tutorial. The only options I get are shown below in this screen grab (note I chose to only add one label and leave out image for the purpose of my application).
Can anyone please let me know what Im doing wrong or how else I can create this connection? I have Googled it for the last hour and all I could see was how to create IBOutlets.
Alternatively, does anyone know of any tutorials similar to this one? This one suits my needs perfect as I will be creating a view similar to the second part of this tutorial. Like I mentioned Im working with Xcode 5.
Although this might be a little late, I recently just stumbled upon this problem myself and figure out the answer. I used the same tutorial as you, and could not seem to generate the proper options when I did the control + drag.
Instead of dragging the labels to the whitespace of the custom cell, you will be dragging from the Connections tab of the custom cell. To do this:
First, make sure your labels are properly declared in CarTableViewCell.h and synthesize them in CarTableViewCell.m.
Second, change the custom class in the storyboard for the prototype cell from UITableViewCell to CarTableViewCell.
Next, click on the cell prototype in storyboard. Using Utilities, go to the connections tab (the last one with the arrow). If everything is linked properly in your header files, you should see "makeLabel", "modelLabel", and "carImage" under the Outlets section.
Finally, click the little circle next makeLabel and drag it over to the proper label in your custom cell. Do this for modelLabel as well as carImage, just using the associated outlet and label or imageView for each.
This solved my connection problem, and after following the rest of the tutorial, everything worked!
Is your cell a custom cell. If not click on your cell and go to the attribute inspector then under table view cell choose the style as custom
Is your TableViewCell connected to the "CarTableViewCell"?
Click on the cell and make sure the custom class is set to CarTableViewCell.
And your .h file matches the one in the tutorial
#import <UIKit/UIKit.h>
#interface CarTableViewCell : UITableViewCell
#property (nonatomic, strong) IBOutlet UIImageView *carImage;
#property (nonatomic, strong) IBOutlet UILabel *makeLabel;
#property (nonatomic, strong) IBOutlet UILabel *modelLabel;
#end
Try again, and it should be like the tutorial.
-Cong
I'm currently refactoring a couple of view controllers that share a few IBOutlets and IBAction methods. I moved the outlet declarations and the IBAction method into a superclass, cutting these out of the subclasses.
Now, when I open up Interface Builder, I find that I can't see the outlets or actions declared in the superclass. The connections still exist, as I'd wired them up before the refactoring, but they're grayed out. (It's important to note that the connections also WORK, as my action fires on a button press, and my outlets are modified properly.)
The question is, how can I get interface builder to recognize outlets from a superclass? Is this possible, and, if not, what do you all recommend?
(Just for fun, here's my superclass header file:)
#interface TFMainViewController : UIViewController {
UIImageView *logoImage, *thinkfunImage;
UIButton *buyFullButton;
}
#property (nonatomic, retain) IBOutlet UIImageView *logoImage, *thinkfunImage;
#property (nonatomic, retain) IBOutlet UIButton *buyFullButton;
-(IBAction) buyFullVersion;
#end
EDIT: in case anyone's wondering, I'm using Xcode and IB 3.2.5, with the iOS 4.2 SDK.
I didn't realize it was even possible to connect to superclasses in interface builder until about an hour ago. Since this was the only question I could find regarding how to do this, I'll add my answer, even though this question is old. My answer is with regard to Xcode 4, not Xcode 3.
As far as I can tell, you can't connect to outlets in a superclass using the assistant editor, but you can do it by clicking on "File's Owner" in IB. That should show all the outlets in Utilities->Connections Inspector. You can then Ctrl+Click on the outlet in the inspector (click on the '+' sign), and drag it over to your view in IB.
The solution for the problem with the IBOutlet .. is to change the class type to the Base Class in the identity inspector
connect using Control + drag and drop and
change it back to the child class
This works for me
BTW: i used Xcode 6
IB should be able to see outlets from superclasses, I have done this a number of times with no issues. Are you sure you are importing the superclass correctly (using #import instead of #class)? IB needs some way to track back to the superclass.
Switching between the super and subclass in the identity inspector allows you to connect your outlets across the classes. The only issue I found is when you attempt to do this with a UITableViewCell and its subclass. I wanted to re-assign the default textLabel and detailTextLabel instances to labels I create in Interface Builder. The workaround is to create substitute labels and then override the getters to point to these instead.
I'm pretty sure that IB only looks at the actual class you're using to find outlets, and not at superclasses. I think that the easiest solution would be to leave the instance variable declarations in the superclass, but duplicate the #property lines in each subclass.
I'm doing this in XCode 3.2.6. I started with outlets connected to a class, and then made a subclass with additional outlets. When I changed the File's Owner class to the subclass, IB showed the superclass outlets as greyed out. I switched File's Owner to the superclass, then back to the subclass and now all outlets are showing not greyed out.
The simplest way: create interface and implementation files for your subclass(es)!
Perfect example: Juggleware's awesome ShadowButton Subclass of UIButton.
Make sure to create the .h & .m files in your project.
NOTE: There is no need to #import the header files at all since this is simply a class instance of UIButton.
In Interface Builder:
Select the element you which to connect.
Go to Utilities -> Identity Inspector
Change the Class to your subclass (or superclass). NOTE: You might have to type in your subclass name and hit ENTER.
You're done!
Even if you have declared a basic class (UIButton) as IBOutlet in your header file like so...
// YourViewController.h
#interface YourViewController : UIViewController {
IBOutlet UIButton *mybutton;
}
...the class you've set in Interface Builder (ShadowButton) will overwrite it since it's in the view layer.
The best part about this approach is that your code doesn't have any messy dependency issues.
On the project I am currently working, we have a BaseViewController with a UIScrollView as IBOutlet and handles keyboard appearance/disappearance events and slides the content accordingly. At first, I could not connect to that IBOutlet, than solved the problem like this, which is similar to Sosily's answer:
BaseViewController has an IBOutlet, called contentScrollView. I can see 5 previously connected outlets, which are UIScrollViews on other UIViewControllers, created by people who previously worked on the project
I tried to connect my UIScrollView as the contentScrollView. Although my UIViewController is a subclass of BaseViewController, I cannot connect it.
I tried to connect already connected UIScrollViews as the contentScrollView. Although all UIViewControllers are subclasses of BaseViewController, I cannot connect them again, as well. So, I started to look for a trick.
I have created the same contentScrollView IBOutlet on my own UIViewController, connected the scrollView to my own contentScrollView outlet and removed the one that I have just created.
Now the scrollView is connected as contentScrollView to File's Owner, but the only contentScrollView belongs to the BaseViewController. Tested and verified that keyboard events are handled correctly.
I ran into a similar problem with a superclass, but it was due to a bug in Xcode (8.2) where Interface Builder doesn't show outlets in the Connection Inspector if those outlets have been declared with a _Nullable type annotation for Swift compatibility.
Using nullable inside #property's parentheses appears to work around the problem.
This Xcode bug seems to affect outlets in any class (ie. not just superclasses).
I had the same problem, and it turns out it was because in the superclass I had the IBOutlets declared as "_Nullable".
Example:
#property (nonatomic, strong) IBOutlet UITableView *_Nullable mySuperTableView;
When I removed the _Nullable, suddenly the IBOutlets reappeared in IB and all was good again.
(I had only set them to _Nullable because Xcode was complaining "pointer is missing a nullability type specifier"... (don't know why). )