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
Related
When I connect element from xib to header file. It gives me
#property (strong, nonatomic) IBOutlet UITabBarItem *contract;
#property (strong, nonatomic) IBOutlet UITabBarItem *history;
However, when I try to print out the subiew of my tabBar ( type of UITabBar), I am getting 2 UITabBarButton.
My question is what is class of tab bar item.Is it UITabBarItem or UITabBarButton
Firstly: what you're doing is not recommended. You're not meant to rely on private subviews of Apple views, as they can change at any time.
To actually answer the question as posed, it's because UITabBarItem is not actually a view, so won't ever end up in your view hierarchy. What presumably happens somewhere in the UITabBar code is, the UITabBarItems are iterated through, and for each one the system makes a new view of class UITabBarButton, which is a private subclass of UIControl.
You're never meant to access a UITabBarButton directly. As BoltClock was pointing out in the comments, you should rethink your design so that you don't need to do this.
In the following code what is the function of -(IBAction)setLabelPushed:(id)sender;
#import <UIKit/UIKit.h>
#interface BasicIPhoneAppViewController : UIViewController
{
IBOutlet UILabel *myLabel;
IBOutlet UITextField *myTextField;
}
-(IBAction)setLabelPushed:(id)sender;
#end
Actually it is a non-static method. IBAction means that it can be used as a event handler in Interface Builder (it can be linked to some action). You should provide more details, for example the body of setLabelPushed function.
get the value from textfield and show it in the label .I think so......
It is a method you can bind from within the Interface Builder...
http://mobile.tutsplus.com/tutorials/iphone/iphone-sdk-interface-builder-basic-training/
IBAction resolves to "void" and IBOutlet resolves to nothing, but they signify to Xcode and Interface builder that these variables and methods can be used in Interface builder to link UI elements to your code.
If you're not going to be used Interface Builder at all, then you don't need them in your code, but if you are going to use it, then you need to specify IBAction for methods that will be used in IB and IBOutlet for objects that will be used in IB. IBOutlet and IBAction
Sometimes I see the following code into two different formats:
Format 1:
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController {
IBOutlet UILabel *myText;
}
#property (retain, nonatomic) UILabel *myText;
-(IBAction)buttonPressed:(id)sender;
#end
Format 2:
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController {
}
#property (retain, nonatomic) IBOutlet UILabel *myText;
-(IBAction)buttonPressed:(id)sender;
#end
which is the correct format? Why?
To clarify what Hack Saw said, and more directly answer your question, it does not matter whether you put IBOutlet in your property declaration or your instance variable declaration.
What Hack Saw was trying to say is that IBOutlet and IBAction both mean nothing to the compiler (IBAction gets compiled into void). The only reason they are there is for Interface Builder to parse the file and make a list of all objects and methods that you the developer says it should care about.
IBOutlet is a marker for interface builder to find your declarations, and make them available in the drop downs in IB.
They are strictly only required if you want to have IB connect an IB object to a reference in your code, for instance, connecting a button to a UIButton * declaration.
So, the basic idea here is that Interface Builder has a list of objects it knows how to make. You could make those objects in code, but a lot of the time, you don't need more capability than what IB offers, which is actually quite a lot.
In those cases, IB takes care of that object entirely. It allocates it, and sets the various parameters, and takes care of displaying it.
However, you obviously need to be able to talk to it, as well, most of the time. In order to do this, your declare a pointer to the object, like UIButton *mybutton, but in order to let IB know you want to connect up with it, you add IBOutlet to the declaration.
IB lists the variable, you connect the button up to something in File's Owner, or sometimes firstresponder, and then IB saves that connection data, and sets everything up when the nib gets loaded.
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.
I am facing an issue and that is -
I am using tabBarCpntroller in my application. In this there are just two views. Both the views have tables in that.
I am able to display and populate the table in the first view but as I try to connect the delegate of UITable in the IB for the second view and then run the code, it crashes.
PS: I am using the same code as in first view.
Kindly help me out with the suggestions, I would be highly grateful
Thanks in advance!!
By the looks of your question, you need UITableView, not UITable, if this is what you are using, then you will have problems.
in your header, you must define your UITableView as an IBOutlet.
.h
#interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView *myTable;
}
#property (nonatomic, retain) UITableView *myTable;
#end
Once you have done this, build (only) your code, then Interface Builder will see that outlet and you can connect it.