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.
Related
My OS X app written in Objective-C needs to display a varying NSString* variable theString which can get quite large.
I use Xcode IB to build a nib file which displays theString in a NSTextField* object panel declared inside AppDelegate.h like this:
#property (weak) IBOutlet NSTextField *panel;
Now I can set the contents of panel inside AppDelegate.m like this:
self.panel.stringValue = theString;
This all works fine. But I now want to give my text field a scrollbar. So in place of a "Text Field" I choose a "Text View" from the Object Library, and get its blue line to generate me a new declaration of panel which now looks like this:
#property (weak) IBOutlet NSScrollView *panel;
This now no longer works:
self.panel.stringValue = theString;
raising the error: (!) Property 'stringValue' not found on object of type 'NSScrollView*'
How do I need to fixup this statement?
(Might I just say I find the extensive Apple documentation on the topic byzantine and opaque. Why am I being naive to expect a simple answer to this simple question, as it all seems to imply? I must be missing something obvious -- what is it?)
What you got was a NSTextView wrapped inside a NSScrollView. The scrollView is the thing that makes the scrollbars you want. It basically holds a potentially much larger view inside its viewport and shows only small part of it, that you can shift around with the scroll bars. You need to get (another) reference from your code to the NSTextView inside the scrollView. You can find the NSTextView in the hierarchy in IB and attach to that.
This is in the direction of what you want but I think not quite what you need. The textView is a far more advanced control than a simple textField and probably more than you need. You could instead use a custom view by taking a NSScrollView that comes with a default NSView wrapped inside. Then instead of the NSTextView place your NSTextField on the NSView. The issue with this is that then you need to add some code to auto-resize the NSTextField and NSView based on the content of the textField. Once you got that sorted the scrollView will automatically arrange for the scrollbars that you need.
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.
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.
Does anyone know a way to, in a storyboard, load a UIView's contents from another nib? I know I can do this easily with code, but I am trying to figure out how to do more in IB.
I have a storyboard with my main UI layout, I have a UIScrollView and I want to design its contents in IB. The only way I could figure out how to do this was to design the UIView in its own .nib, but then my issue is, how do I load the nib without coding it to do so? Is this even possible? It doesn't seem too far fetched to me.
I'm assuming you simply want to lay out your UIScrollView in IB, that a .nib is mentioned because that was an approach you were exploring, but if you could do this strictly in your storyboard that would be acceptable, if not preferable:
First, create a new file in Xcode that is a subclass of UIScrollView.
In your storyboard, drag a UIScrollView out to the scene (viewcontroller) where you want to display this scroll view.
In the Identity inspector, set the Custom Class of the UIScrollView to your subclass of UIScrollView.
Create an outlet for this UIScrollView by ctrl+dragging the UIScrollView into the .h file of the ViewController subclass it's displayed in. Name it something like myScrollView
In your ViewController's -viewDidLoad method, set the contentSize property of the UIScrollView to whatever size you want it to be. So it will look something like:
self.myScrollView.contentSize = CGSizeMake(800,800);
Now, drag out UI objects to your UIScrollView and design.
IMPORTANT: To create outlets to these objects is a little tricky. Let's say you've dragged out a UILabel. You need to manually go into your UIScrollView subclass and add to the .h
#property (nonatomic, weak) IBOutlet UILabel* myLabel;
and to the .m
#synthesize myLabel = _myLabel;
Now you need to get your outline view on screen along with your storyboard and ctrl+drag FROM YOUR SCROLL VIEW TO YOUR LABEL to create an outlet. This is kind of the reverse of what you're used to.
Now you can reference that outlet from within the viewcontroller or the scrollview subclass . For instance, in the viewcontroller -viewDidLoad you could say:
self.scrollView.myLabel.text = #"Hello World";
HTH!
If what you want is to edit inside a scrollview from IB, it's a pain, but doable.
Have a look at my answer on this question.
Add a generic UIView in the IB, setting its custom class to the name of your nib file.
Replace GradientControl with the name of your nib file (minus the '.xib').
I am having trouble displaying data in my table.
Preamble:
TableView placed on the storyboard
TableView linked to a #property (strong, nonatomic) IBOutlet UITableView *myTable;
.m file contains both required methods and content to be displayed
Controller conforms to <UITableViewDataSource>
I suspect i am not setting up the dataSource in the right place. Where in a UIViewController should it be set, when initialization happens from the StoryBoard? I placed it in the -(void)viewWillAppear:(BOOL)animated, however DataSource was not set. Same goes for init.
[myTable setDataSource:self];
If the view is loaded with the help of storyboard (initialization does not happen as part of init method) .. where should table's dataSource be set?
The controller's -viewDidLoad method would be a good option. That method is meant to perform any initialization that has to be deferred until the view is loaded.
I'm not sure what you mean by 'did not take.' Is the table's data source not set to your controller?