IBOutlet not showing in File's Owner/ IB - iphone

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.

Related

iOS 6 issue during setting text on a label

I've a problem with some label. I made a public method that takes information from a table view and shows this info in 3 label, a text view and it load a pic from the web. I setup all the variable in the table view didSelectRowAtIndexPath method, but I'm having some issue to display that info. I made so:
in the table view controller I called the other method so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.detailCharacterViewController = [[DetailCharacterViewController alloc] init];
[self.detailCharacterViewController setupDetailViewControllerWithName:[self.arrayCharacters[indexPath.row] objectForKey:#"name"] andSurname:[self.arrayCharacters[indexPath.row] objectForKey:#"surname"] andKind:[self.arrayCharacters[indexPath.row] objectForKey:#"kind"] andDescription:[self.arrayCharacters[indexPath.row] objectForKey:#"description"] andImage:[self.arrayCharacters[indexPath.row] objectForKey:#"URLpic"]];
}
and I implemented the method so:
- (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url {
NSLog(#"name = %#", name);
self.labelName.text = name;
self.labelSurname.text = surname;
self.labelKind.text = kind;
self.textDescription.text = description;
NSURL *urlPic = [NSURL URLWithString:url];
NSData *dataPic = [NSData dataWithContentsOfURL:urlPic];
[self.imagePic setImage:[UIImage imageWithData:dataPic]];
}
If I look to the log i see the right things, but if I look to the GUI on iPhone or iPhone simulator it will remain blank. What's wrong with this code?
Thank you for the suggestion.
#Alex Blundell
#import <UIKit/UIKit.h>
#interface DetailCharacterViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *labelName;
#property (weak, nonatomic) IBOutlet UILabel *labelSurname;
#property (weak, nonatomic) IBOutlet UILabel *labelKind;
#property (weak, nonatomic) IBOutlet UIImageView *imagePic;
#property (weak, nonatomic) IBOutlet UITextView *textDescription;
- (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url;
#end
The problem is that your DetailCharacterViewController's view is not loaded yet when you call setupDetailViewControllerWithName:..., so none of the outlets are connected (yet). Instantiating a view controller via alloc-init does not load its view automatically.
You could force loading the view by calling [self view] at the beginning of your setup method. This works because accessing the view property will automatically load the view if it wasn't loaded before.
Alternatively, you could make the name, surname, etc. NSString properties of the view controller and set the corresponding labels in viewDidLoad.
Are you using Interface Builder/Storyboards to design your interface? Have you made sure to connect the IBOutlets for each UITextField/View?
You should identify the objects in the header file on your view controller class, and ensure they're prefixed by IBOutlet for them to appear in Interface Builders connections pane. E.g.
IBOutlet UITextField labelName;
[...]
Then you need to go to IB and go to the connections pane for the view controller to connect each text field/view.
This problem happened to me as well.
It has to do with the fact that iOS actually hooks up your outlets really really late.
If you put a breakpoint in your setupDetailViewControllerWithName: and check your IBOutlet variables, they will be nil. That's why you are seeing a blank view. (The good old nil erroring)
The work-around I will do is to declare properties in the DetailCharacterViewController class. (Such as #property (copy, nonatomic) NSString* name).
And in the place where you are calling setupDetailViewControllerWithName:, set those properties instead such as:
self.detailCharacterViewController.name = name;
Finally in your DetailCharacterViewController's viewDidLoad:, you set the values of the labels using the saved properties. (The outlets are for sure hooked up then).
(By the way, this problem exists for prepareForSegue: as well. The destination view controller's outlets are all still nil in prepareForSegue:. So you cannot set them directly there yet)

control an object from different .h on main window

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"];

Cannot see my label outlet when draging file owner in Interface builder

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

IBAction is not shown in IB?

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...

iPhone + access Controls from other class

I have classes: PropertyCalcViewController .m & .h
In the .h I have
IBOutlet UIButton *btnGo;
#property (nonatomic, retain) IBOutlet UIButton *btnGo;
and in the .m file I have
#synthesize *btnGo;
Now I also have another class Manager .m & .h.
What I want to do is that access btnGo from the Manager class and remove it from PropertyCalcViewController like
[btnGo removeFromSuperView]
How can I do this?
To access a property, you use the "dot-syntax":
[the_view_ctrler.btnGo removeFromSuperview];
Also, I believe you mean #synthesize btnGo;, instead of #synthesize *btnGo; which is a syntax-error.
Insure that btnGo has been properly linked up in Interface Builder. Simple but common oversight.