It's been awhile since I've used Xcode and I resumed an old project I was working on awhile ago. I created a new UITableViewCell subclass. In my storyboard, I dragged a UITableViewCell onto my UITableView of my UIViewController. I changed the type of the UITableViewCell to my subclass, but when I control + drag from the UITableViewCell subclass to the UITextField, it doesn't allow me to make the connection.
.h of my UITableViewCell custom subclass
#property (nonatomic, weak) IBOutlet UITextField *titleTextField;
I must be going crazy because I thought this was something that just worked. I saw in another UIViewController that there is a custom subclass for the UITableView when I worked on this project last. I changed the subclass that was having the problem to that type of UITableViewCell subclass and I'm still not able to ctrl+drag to make the IBOutlet connection. Am I missing something here? Wasn't this something that always worked this way? Is there something new I'm not aware of? I tried using the assistant editor as well to drag it to the code, but that doesn't work either. I went back to the UITableViewCell subclass that DOES have a connection already made from when I last worked on this, and I tried ctrl+dragging to the label again, and it doesn't bring up the menu on which outlet I want to connect to either.
Another thing that is weird, is when I'm trying to type the custom class of my UITableViewCell that is already created, even though I built my project, it doesn't autocomplete it in the Class field. I'm not sure if my Xcode is having problems. Also, I don't know if this matters, but in my UITableViewCell, I Have some standard UITableViewCells as well. Any thoughts? Thanks.
It looks like all I had to do for my class name to appear in the drop down was to quit Xcode and come back in. I thought things like that would have been fixed in the IDE.
I found that I could still add the connections in the connections inspector. I don't know why they removed the very easy ctrl+drag from the left hand side of the storyboard unless I'm missing something.
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.
(Link to errors here: http://imgur.com/a/AF87N)
I'm starting to work on iOS development, and I'm relatively new.
I was looking for tutorials on how to display web content in the app, and so I used the UIWebView.
In the tutorial I found I followed the steps exactly, but when I went to do the last step (linking the outlet) I got an error.
The two files I edited are DataViewController.h and DataViewController.m
This is the tutorial I followed: http://www.youtube.com/watch?v=NFffF9tRbak
I'm using XCode 4.6
Am I doing something wrong?
Renaming may still cause some erors, there is a chance, so its better to set the connections again.its quite simple.
You can solve this by following these steps:
1.
Click on the cross sign left to Web View , that will remove the invalid outlet.
2.then, connect the existing #property(nonatomic, retain) IBOutlet UIWebView *myWebView by control dragging the '+' sign left to the property outlet to your webview in the Interface Builder.
This will solve your problem, happens just because you are new to xcode. Will get better as soon as you get familiar.
EDIT:If its still not clear, see the screen shots below;
your outlet in yourviewcontroller.h may be like this now,
and in your xib,
it may look like this.
So what you should do is, just control drag the while blank circle left to #property outlet (first image) to the webview in your xib (highlightened one in second image). It will connect itself.
hope its clear now
Regards
Change your outlet name from webView to myWebView in outlets
Edit:
or change your UIWebView object name from myWebView to webView in your code
I'm really a newbie on iOS and I don't know how to connect the UITextView object to the textview control on *.xib file? Is there any way to set the unique ID to a control on iOS?
Currently, I have declare an IBTextView as below:
HelloViewControler.h file:
#interface HelloViewController : UIViewController{
IBOutlet UITextView *txtTextMe;
}
#property (retain,atomic) UITextView *txtTextMe;
- (IBAction)buttonPressed:(id)sender;
#end
HelloViewControler.m:
#synthesize txtTextMe;
- (IBAction)buttonPressed:(id)sender{
txtTextMe.text = #"Button clicked";
}
Code to update a string to textview control:
txtTextMe.text = #"Button clicked";
No Error. But when I run the code, the string "Button Clicked" wasn't updated to the textview.
Hold CTRL and click and drag from the item in the .xib into the code. This will create either an IBOutlet or IBAction (you chose via popup) and link it to the object on the .xib.
It can also be done via the left hand inspector if you have already created the code.
If you are new to iOS programming and Xcode I would very strongly recommend you look at Apple's tutorials on the developer portal. They have some excellent introductory guides with step by step instructions. The second one covers using storyboards and is a really great introduction to storyboards, Xcode and the iOS SDK - link below.
Your Second iOS App: Storyboards
Right-click on the textview control in the NIB file. A HUD-style menu should appear.
Under "Referencing Outlets", drag from the circle to the right of "New Referencing Outlet" to "File's Owner" in the "Placeholders" section to the left. When you release the mouse button, another popup menu should appear.
Pick txtTextMe from the menu.
Build and enjoy :-)
This is my fault. I drag a UITextField to *.xib file but I declare an IBTextView in my code. Thanks all.
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). )