Can't connect a button\label with variable\outlet in storyboard - objective-c

I created 2 View Controllers: on the first I created a button when click on it you will open another View Controller with button and label. I already created outlet and variable for them.
My question is: when I'm trying to connect the button\label with variable\outlet I can't see selection around the button\label -> I mean that I can't connect them all. Why?
P.S. DON'T PUT A MINUS I JUST NEW PROGRAMMER!

Can you post your IBOutlet declarations?
You have to declare UIButtons like this to make them work (connect) in Interface Builder :
#property (nonatomic, strong) IBOutlet UIButton *aButton;
For a label its just the same :
#property (nonatomic, strong) IBOutlet UILabel *aLabel;
I think you have either forgotten to write IBOutlet or your variable type is wrong.

Ok! I resolved the task.
I just needed to create a new Objective-C class, select that new class in Identity Inspector of the second View Controller and write all code in that new class.

I missed this one too.
For anyone still confused, select the View Controller (the yellow box) in your Storyboard and then under Inspector select the Identity Inspector. See images.
Now you will be able to connect up the IBOutlet items in your interface .h file.

Related

How to display an object created in one class in another class in Objective-C?

I have created a UIPickerView in a view controller called ActivityLevelPickerViewController. I want to get this picker view to display in a view controller called RegisterViewController.
How do I call the picker view in RegisterViewContrller?
There are two options. One is to just copy over all the code related to the pickerView from ActivityLevelPickerViewController to your RegisterViewController. The other option is to create a new UIPickerView subclass and move all the code related to populating the rows there. The nice thing about creating a subclass is that if you want to make a change to your picker, you can just change it once rather than in every view controller. The property declaration would look something like this:
#property (weak, nonatomic) IBOutlet MyPickerViewSubclass *pickerView;
Don't forget to import your picker view subclass in your view controller if you go with the subclassing option.

Xcode - My app is acting weird

I have a project that I got handed me (half working / half not working) and I have never seen something like to this before.
I have a storyboard and one of the scenes is called 'CompletionVC' and inside that scene I have this:
and in my header file for this scene I have this:
UIPickerViewDataSource,UIAlertViewDelegate>
{
IBOutlet UIButton *areaButton;
IBOutlet UIButton *unitButton;
IBOutlet UIView *searchView;
__weak IBOutlet UILabel *userLabel;
}
and none of those IBOutlets have any Referencing Outlets.
and in my .m file for this scene I have this:
- (IBAction)AreaButtonPressed:(UIButton *)sender
and this does not have a sentEvent assigned to it.
But somehow they are still appearing in my app, which is fine, but I want to adjust them and I cant find them anywhere....based off the information I provided, can someone give me a tip or two about where I these IBOutlets? I would like to make some adjustments, but I can't find them anywhere...also sometimes these IBOutlets have a Sent Event and Referencing Outlet, but it was referencing a file that is not there. The IBOutlets appear and are functional...weird eh?

Can not link IBaction or IBOutlet

when I try to create an IBOutlet or an IBAction by linking my interface to the header file, I don't get the option to create one.
Yeah, this COULD be a duplicate but I havent found my answer yet on ANY other post!
Thanks :)
#property (assign) IBOutlet NSWindow *window;
- (IBAction)calculateClicked:(id)sender;
#property (weak) IBOutlet NSTextField *ATextField;
#property (weak) IBOutlet NSTextField *BTextField;
#property (weak) IBOutlet NSTextField *CTextField;
I'm not sure what kind of object you wanted to add your outlets/actions to, but one might infer from the presence of the window reference that you're trying to add that to your app delegate. In that case, you just need to make sure that your app delegate appears in the list of objects, and that you've specified the base class for that app delegate:
If, however, you were using some custom controller object, you would drag an generic object from the library to your NIB's list of objects. Then specify the custom controller class for that object (MyController in my example):
Having done that, when you drag your outlets/actions from the window to the assistant editor, in addition to the app delegate, your custom controller object interface/implementation files will be options that you can use.
My original answer was an iOS-centric answer. The above should describe the Cocoa equivalent. I'll keep this original answer here for reference.
Original answer:
In Interface Builder, make sure to specify the base class for the object you're linking the outlets to. If putting these outlets in a view controller, make sure your storyboard's scene has the view controller's class defined. And it's a little easier if your assistant editor is set to "automatic":
The above screen snapshot is relevant if you're using storyboards. If using NIBs, the idea is the same, but you need to make sure you set the NIB's file owner:
If your IBOutlet references are in a UIView subclass, you analogously have to specify the base class for your storyboard scene's view (or the NIB's view).
I've seen Xcode occasionally do this (bug). Closing/reopening Xcode has fixed it for me before.
Also, make sure that your interface file is Class is pointing to this class/header.

How do I make connections to custom properties in my nib?

I created a custom view. It has a delegate that it will notify when some of its buttons are pressed.
I added this to the view controller's viewDidLoad:
self.myCustomView.delegate=self;
So far everything works fine.
But that's not cool enough. I want to do it the table view style where I can just right drag from the view to the File's Owner and (ta-da!) it's automatically set.
Add the IBOutlet keyword to the delegate property of your class:
#property (nonatomic, assign) IBOutlet id<MyViewDelegate> delegate;
The IBOutlet keyword tells the nib editor to let you make a connection to that property.
You could also say this:
#property (nonatomic, assign) IBOutlet MyView *delegate;
And then IB will only allow you to connect it to a MyView. But a protocol or id is more flexible.
EDIT: One point has been lost due to focus on IB
You said:
I created a custom view. It has a delegate that it will notify when some of its buttons are pressed.
Receiving button events is the role of a view controller, sometimes however a delegate will be used for finer grained control of certain events.
In general dont create a delegate for button presses on a view that is a primary window in which case you should be handling your button events in a ViewController. Buttons sit on a parent view that will forward events up the responder chain (you still need to connect them to a target). Im not saying you shouldn't ever use the delegate pattern for button presses but, buttons have their own connections to view controllers in IB with drag and drop as you wish. But there are situations like yours which are perfectly valid.

How do I update a UITextView in my view controller?

I have tried to use
self.myUITextView.text = #"hi";
to update my UITextView in my Nib file.
However, the original text of the UITextView is still on the screen. How do I update a UITextView in my view controller?
Give proper connection (IBOutLet) from xib to your view controller. You have missed the IBOutLet connection of UITextView from nib to controller as i guess.
I am sure you must have declared the UITextView as
IBOutlet UITextView *myUITextView;
and also properly connected it to your XIB.
Then declare the following property in your .h file
#property (nonatomic, retain) IBOutlet UITextView *myUITextView;
and synthesize it in your .m file
#synthesize myUITextView;
Now try to change the text to whatever you want. In your case
myUITextView.text = #"hi";
You can use the set property of uitextview [self.myUITextView setText:#"Hi Updated"];
in -(Void)viewWillApper method.
Make sure your UITextView IBOutlet in IB is hooked up with a valid connection to your controller's property.
Wait until "viewDidLoad" is called to change the text (before that, you have no guarantee the text view is loaded in memory).
Change the text property (as you did).
You are doing wrong thing....You are specifying value in load method...So even though you have changed the value, when you try to load that view again...viewDidload method will be called and the new value will be replaced by the original value....
Instead of setting value in viewDidload..Make some method or put some button ang in its click method,Set the value and store it somewhere......You are doing totally wrong thing.