xcode IBOutlet won't connect to codes - ios

I am using xcode 4.3
I have a huge problem:
I started creating an application using storyboard for the ipad. At first i added my objects in interface builder, and then I dragged the blue line to the .h file and xcode made the connection and created a:
#property (strong, nonatomic) IBOutlet UIButton *button1;
with the filled up circle.
But after a few days, I tried to add a UIScrollView. I added the object to the storyboard, and dragged the line, but it would not connect and create a property. So I made first the codes,and tried to link, but same problem. So I deleated the scroll view and inserted again a button and lable. BUT NOW ANY OBJECT WON'T LINK TO THE CODES IN ANY WAY!!! WHY? To solve the problem I have to start again from the biginning!!
I create:
#property (strong, nonatomic) IBOutlet UIButton *button2;
drag the line: NO
drag to view controller: NO
did the opposite: NO
WHY???

You need to make the scene an instance of class ViewController instead of UIViewController, which is the default. You can change this in the identity inspector (third tab in the utilities)

If you're trying to drag the line to anything other than a button you're not going to have any success.
If you want to drag the line to a scrollview, you need to change the declaration to
#property (strong, nonatomic) IBOutlet UIScrollview *scrollView;
//^^^^^^^^^^^^ this type determines what it links to in interface-builder

Related

Why Xcode 9 creates my outlet (strong, nonatomic) by default

When I control-drag outlet from the storyboard, I got the strong property by default. I'm using Xcode 9.4.1. The following code is what it looks like. Is it because of XCode Swift compatibility as in Swift it makes sense to create strong.
#property (strong, nonatomic) IBOutlet UILabel *lbl
The default value should be weak, but if you once change it manually to strong as shown in the photo, the default value changes to strong, so you need to manually put it back to weak.

Adding an IBOutlet to custom class

I'm learning iOS and am new to the concept of IBOutlets - so I'm making a simple app in an attempt to learn how it works.
The problem:
I created an interface using a Storyboard and want to hook it up to an IBOutlet in my custom class ("TapCounter") in order to access (and be able to set) its text field. However when trying to hook my class' #property (nonatomic, weak, readwrite) IBOutlet UILabel* numberOfTapsTextField;
up to the UILabel in the Storyboard the line does not want to attach to the label.
Here is an image of the situation: http://gyazo.com/0050ef0a78772adcad214cdc4603f932 (Dragging a line from the hollow circle next to the #property to the label in the Storyboard does not snap to it).
I have not modified anything of the boilerplate code except for that I added #import "TapCounter.h" in viewController.m
This feels like it should be a very simple thing - but again; I am new to this.
EDIT
Have I got this idea wrong? Should all IBOutlets be in the viewController of a view (and simply be accessed by other custom classes)?
It work like this:
create a CustomView class
add a view in you storyBoard
set class for this custom view as CustomView in identity inspector cmd+opt+3
Create an IBOutlate of your component inside customView
Link those component with respective outlet
Refer Image:

Sharing same properties of ViewController for iPhone Stroryboard and iPad Story Board

I'm developing a universal application.
in the first view, I have the login screen for the user.
In iPhone storyBoard, I have added 2 text field and one button( login check).
I have added properties in ViewController.h file by dragging those objects(Ctrl key + Dragg) to .h file.
I have added code for login check and it is working fine for iPhone.
This is the code in ViewController.h
#property (strong, nonatomic) IBOutlet UITextField *txtUserId;
#property (strong, nonatomic) IBOutlet UITextField *txtUserPwd;
#property (strong, nonatomic) IBOutlet UIButton *btnLogin;
In the iPad storyBoard, I have added 2 text field( userid and password) and i button for login.
So now, I want to bind those objects with the veriable which I declared already in ViewController.h file in case of iPhone.
My questions:
1. What is the right way to bind properties for both storyboard?
2. Am I on the right direction or should I think in a different way to do it?
I am new with iPhone development. Please help.
Thanks.
--Amin
Give your custom class name to storyboard from storyboard utility.
Ensure to link both the storyboards with your Login class. Now go to iPad storyboard, right click the view components and drag them and hover on to the properties you have declared already.

The storyboard is automatically copied to the new project

I have a project in Xcode, lets name it A, in which I have a story board and several views. I only need part of project A. Hence, I made a new project, B, and made a new UIViewController, with xib, and copied the two UIViews from project A to B.
It looks like this now, where RPM Display and Speed Display are copied (by dragging from xib) from A to B.
AnalogDisplayContainer belongs to the class PD_AnalogDisplayContainer, and we have two outlets in class PD_AnalogDisplayContainer:
#property (nonatomic,assign) IBOutlet PD_AnalogDisplay* speedDisplay;
#property (nonatomic,assign) IBOutlet PD_AnalogDisplay* rpmDisplay;
which are connected to the respective views in xib. (We have exactly the same code in project A.) These UIViews have some UILabels as well, which are automatically copied in project B, and I need them as well. You see them here:
Up to here, the description of what I did. Now, the problem:
I have three outlets in class PD_AnalogDisplay.
#property (nonatomic, assign) IBOutlet UILabel* unitLabel;
#property (nonatomic, assign) IBOutlet UILabel* digitalIntegerValue;
#property (nonatomic, assign) IBOutlet UILabel* digitalFloatValue;
However, so strangely, when I click on the small point beside these outlets, it shows me the connections to story board,
and when I click on the connection, I see the whole storyboard and views from project A.
In addition, these connections are not shown when I click on xib.
I searched in project B, there is no storyboard, or all these things I see in the previous picture, in form of code. So I don't know where it all come from. And I get the run time error:
loaded the "RPMViewController" nib but the view outlet was not set.
Yes, it brings previous reference wherever you copy it.
It is happening because the class name is same in project A and B.
Create class name in project B other than class name in project A or slightly change variable name.
Assign that class to your xib file.
You must recreate the IBOutletes from xib file.
Just copy the interface components not the code in .h file.
Observations:
When I move project A to another location makes trick, reference destroyes.

Cannot connect a property to storyboard

I am building a master detail iPad application. Trying to connect a property declared in my view controller's.h file.
#property (weak, nonatomic) IBOutlet UILabel *aboutGame;
#property (weak, nonatomic) IBOutlet UITextField *gameDescription;
The file owner has been set as I am able to connect the *aboutGame property to a label on my storyboard. Trying to set the Text field to an element just does not seem to work. Am I missing something here?
The following shows up when attempting to connect the textfield. (Note the same is going wrong when trying to link a UIImageView also)
You have UITextField in definition and UITextView on Interface builder. So it is not showing you the option to connect.
Try like this:
#property (weak, nonatomic) IBOutlet UITextView *gameDescription;

Resources