I have this in my .h controller
#interface helloViewController : UIViewController {
IBOutlet UIlabel *label;
}
-(IBAction)hello:sender(id);
#end
I opened the corresponding .xib file and I could drag and associate the button -hello to the file owner but trying to associate the label doesn't work: it suggests me to associate -view outlet instead why ?
Your method declaration should be:
-(IBAction)hello:(id)sender;
Also, UILabel needs a capital L
IBOutlet UILabel *label
Related
i want to get the label value by using perform button action using uicollectionviewcell in iOS. i have four label add as subview to uibutton in uicollectionviewcell. how to get the selected index uilabel value using button action.
You have to create a custom collection view cell class subclassed from UICollectionViewCell.In that class you can create labels and buttons from the storyboard.
#import <UIKit/UIKit.h>
#interface AudioListViewCell : UICollectionViewCell
#property (retain, nonatomic) IBOutlet UILabel *lbl1;
#property (retain, nonatomic) IBOutlet UILabel *lbl2;
#property (retain, nonatomic) IBOutlet UILabel *lbl3;
#property (retain, nonatomic) IBOutlet UIButton *button;
#end
Change the Class name of collectionview cell in story board as custom cell class name.Here AudioListViewCell.
In your viewcontroller in the collection view delegate method "didSelectItemAtIndexPath" you can get the labels text vlaue.This is one approach.
If you want to get the label text in button click, you have to add selector for the button in collectionvew cell and each buttons tag value is same as collection view index. Then You can get each label inside a button using the followng code.
for (UILabel * lbl in button.subviews) {
if(lbl1.tag == uniqueLabelTag1)strVal1= lbl1.text;
else if(lbl2.tag == uniqueLabelTag2)strVal2= lbl2.text;
else if (lbl3.tag == uniqueLabelTag3) strVal3 = lbl3.text;
}
You can create label tag from button tag ie. for example if your button tag of first collection view cell is 1 then your lbl1 tag can 1100, lbl2 tag can 1200 and lbl3 tag can 1300.If second button tag will be 2 then lbl1 tag can 2100, lbl2 can 2200 and lbl3 tag can 2300 and so on.
In my .h file I have this:
#interface {
UILabel *questionLabel_;
}
#property (nonatomic, retain) IBOutlet UILabel *questionLabel;
In my .mm file I have this:
#synthesize questionLabel = questionLabel_;
When I go to the xib file I see no evidence of questionLabel in the File Owner. Nor can I connect a UILabel by ctrl dragging to File Owner or First Responder.
It is though working with two UIButtons I have created.
Ideas?
You should set appropriate class of your File's Owner.
Open Utilities -> Identity Inspector -> Custom Class -> Class -> Select your class.
After that you will be able to set outlets.
my application is window based application in objective-c
I have appdelegate file (.h and .m) and controller (.h and .m)
the program load the window view from the appdelegate file and shows the objects (slider, labels) which defined in controller so:
didFinishLaunchingWithOptions in appdelegate
the label in controller
all i need to know how can i get control on the label from that function.
If you establish the label as a property with getter and setter methods:
in controller.h:
{
IBOutlet UILabel *label;
}
#property(nonatomic, retain) IBOutlet UILabel *label;
in controller.m:
#synthesize label;
Then you can simply call the label from an instantiation of controller:
[controller.label setText:#"For example, you can set the text"];
i have done like
#interface tabViewController : UIViewController
{
IBOutlet UIButton* button_first;
IBOutlet UIButton* button_second;
IBOutlet UIButton* button_third;
IBOutlet UIButton* home;
}
but i could not in file owner those button? what i have to do? any help please? i have set everything correctly (viewcontroller, view)...the day before it was working...i tried in interface builder to reload classes etc...why it happens?
You should have this:
VC Header file:
#interface tabViewController : UIViewController
{
IBOutlet UIButton* button_first;
IBOutlet UIButton* button_second;
IBOutlet UIButton* button_third;
IBOutlet UIButton* home;
}
- (IBAction) ButtonMethod;
VC .m file:
- (IBAction) ButtonMethod
{
// Code goes here
}
You should now be able to link to the "ButtonMethod" in Interface Builder. Right click the button, click on the circle next to "Touch Up Inside" and link it to "ButtonMethod".
Hope that helps.
EDIT:
This images doesn't show the blue line that appears when selecting but shows what you have to press:
Did you declare them as properties?
Using:
in .h-fle
#property(nonatomic, retain) UIButton *button_first;
And in .m-file:
#synthesize button_first?
?
have a look at the nib file. may be you have changed the class of that nib file.
Check out whether you see tabViewController in fornt of File's owner.
I am sure you have changed the class so the change is not getting reflected of IBOUTLET in files owner.
and as told by #GUBB its not at all required to set hte property and synthesis of the stuffs..
hAPPY cODING...
I am trying to use UITabController as may controller in my main window and add navigation controllers to some tab bar items.
For example, the first tab has a navigation controller with table view:
alt text http://www.freeimagehosting.net/uploads/f3ad987c86.png
The SettingsViewController is associated with its own NIB file, where a table view is defined. Within that xib file, I have a table view and set it to the outlet of SettingsViewController class property myTableView.
Here are my h files:
// header file for SettingViewController class
#interface SettingsViewController :
UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *myTableView;
// other codes vars
}
#property (nonatomic, retain) IBOutlet UITableView *myTableView;
// ...
#end
// header for main app delegate
#interface MainAppDelegate :
NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
// ...
}
#property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
// ...
#end
In my SettingsViewController.xib file, through IB, I linked outlet myTableView to the xib's file owner, ie, SettingViewController class:
alt text http://www.freeimagehosting.net/uploads/e577d35137.png
The problem is that in the main xib file, for the SettingsViewController navigation, there is one outlet myTableView. I am not sure if I have to set this to somewhere?
The exception I get is "[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SettingsViewController" nib but the view outlet was not set."
SettingsViewController already has a view property. Are you sure this one is hooked up in Interface Builder? (You probably want it to be hooked up to your UITableView.)