What is the use of IBoutlet in ios? [duplicate] - iphone

This question already has answers here:
IBOutlet and IBAction
(11 answers)
Closed 9 years ago.
I am very well know about full form of IB but i want to know the exact use of IBoutlet
what is the use of IBoutlet in ios in iPhone apps ?

You need to declare a variable or a property as an IBOutlet to relate it to the objects that you define in your XIB. ....
Think of the view defined in the XIB as a separate routines that are hidden to your code.
The objects - UItextfields, UIImageview etc. that are defined in the XIB are created outside your code (.m ) file IBOutlet allows you to refer to them in your code.

IBOutlet is macro that define variables and methods that are related to in Interface Builder.

Related

IBAction and IBOutlet Clarification

I am new to Xcode and I am wondering, what does IBAction and IBOutlet do? I've tried doing simple task like 'hello world' but it seems I stuff it up. I am making app that involves a questionnaire that links to a database.
IBAction is used for Methods which performs as a result of any Action for example Button Press.
-(IBAction) buttonPress : (id) sender;
IBOutlet is used for UI related objects like Button,label, View etc.
IBOutlet UILabel *nameLabel;
Note: If you are using XIB for development, you should make use of IBAction and IBOutlet. Otherwise you will not able to map objects and methods on XIB. If you are developing everything by coding then IBAction and IBOutlet are optional.
As mentioned in the answer linked above: "IBAction and IBOutlet are macros defined to denote variables and methods that can be referred to in Interface Builder."
However in layman's terms and a simple way to think of them -
IBActions mark the methods that will be called when an event (e.g. touch down) is triggered on one of your interface builder controls (e.g. button, switch etc).
IBOutlets mark the variable references for your interface builder controls.
Outlets allow you to programatically interact with controls you layout on interface builder.

Issue with creating IBOutlet in storyboard

I have created a UICollectionViewController custom class , and I inserted an UIImageView into the cell , then created an IBOutlet :
#property (weak , nonatomic) IBOutlet UIImageView *imageCell;
but when I compile the project , debugger gives me this error :
Thanks .
You need to create a custom class - the child of UIImageView. Something like MyCustomImageView and set it to the outlet's class. And one more thing - you should better create an outlets with strong modifier. Also take a look at the link provided in comment to your question more information on your question

Controlls are not displaying in interface builder?

i am facing a problem with IBOutlet,please Respected developers help me out, as i am fresher in iphone
for eg.
i declared buttons or controls with IBOutlet in .h file ,but many times interface builder is not showing the controls so i use to exit the application and reopen it again and i found it
so is there any thing i am missing.
thanks in advance...
Did you save your files? A mistake a lot of people new to iOS/Mac development don't realize is that Interface Builder will not show the IBOutlets unless you have saved the files first. So anytime you add an IBOutlet, make sure you save your header file before diving into Interface Builder.
How are you declaring your outlets? Also, what do you mean by "interface builder is not showing the controls"? If you have the following code:
#interface MyViewController : UIViewController {
IBOutlet UIButton *myButton;
IBOutlet UISlider *mySlider;
}
// Properties
// Methods
#end
In IB's connection inspector the outlets should show up and allow you to connect them to valid UI objects. Could you please clarify your issue?

In IB, I created a table and now want to assign a variable to it

I now want to refer to the table, but there isn't a variable in my .h file as it wasn't required when originally created. The table works great, can add/display/etc.
I tried adding "myTable" to the .h and then linking in IB (the table was linked to "view" and I could/did select "myTable"), but my first try didn't work and I was afraid of messing up my (somewhat) working app ;-)
Hope the question makes sense!!!
thx!
Simply use
IBOutlet UITableView * myTableView;
in your .h file i.e Declaration file.You can now access myTableView in IB.You can now create the object for this TableView.
If I understand you correctly, you want to link the table with your code. If that's the case, then in your header file you need to add a property like so
#property(nonatomic, retain) IBOutlet
UITableView *myTable;
And then synthesize it in your .m file like so
#synthesize myTable;
Once you've done that you will be able to link it up in interface builder. But bare in mind that if you want to populate/interact with the table further you need to set the data source/delegate of your table to your file's owner. Here is a tutorial on how to do that - http://www.switchonthecode.com/tutorials/how-to-create-and-populate-a-uitableview
Does that answer your question?
If your controller is a UITableViewController, just use its tableView property.
The question doesn't entirely make sense because it's not clear what "the table works great..." means if you don't have any reference to it in your .h file. I'll assume you do have an iVar of class UITableView that is defined as an IBAction and you've implemented the table view dataSource and delegate protocols in your view controller implementation. If you have not then the table cannot display any data.
First, if you have an iVar defined you can just refer to the iVar directly. If you prefer a property you can create one.
If your view controller is a UITableViewController you don't need to do anything, the property tableView is already defined for you and you can refer to the table with the tableView property.
If your view controller is something else, you can create a property as follows in your .h file:
#property (nonatomic, retain) UITableView * myTableView;
and in your .m
#synthesize myTableView;
You can then refer to your tableView with:
self.myTableView;
Replace myTableView with the name of your tableView iVar. If you need to connect your tableView in IB to the myTableView property then instead define the property as:
#property (nonatomic, retain) IBOutlet UITableView * myTableView;
Once you've done this, edit your UI in IB and connect the tableView outlet to the myTableView property. You will also need to assign the tableView dataSource and delegate correctly. This is getting a bit beyond your question. Apple's Table View Controller Programming Guide has great docs on this.

IBOutlet keyword strictly required?

I am pretty new to iphone programming therefore I apologize if my question could result trivial or obscure.
In many examples and tutorials I have seen that in the declaration of the outlets within Xcode (interface section of the view controller) the keyword "IBOutlet" is used or it is not, in conjunction with the class the outlet belongs to, apparently without a relevant difference.
e.g.
IBOutlet UIButton * myButton;
or
UIButton *myButton;
I have seen by myself in my experiments that both ways seem to work the same (provided that in both cases I set the proper connections in IB, and declare the property and synthesize it)
Anyone could tell me if there is a relevant difference and different behavior between the two statements?
Thank you
IBOutlet is defined the following way:
#define IBOutlet
So it has no impact on the running code, and its only purpose is to allow Interface Builder automatically determine it while parsing class header. Without IBOutlet keyword in header you will need to declare it in IB Inspector's Identity tab to make it avaliable to be connected to interface elements.