Reputation: 436
I'm actually in big troubles on how to get the Text from a TextField
(and optionally a TextView
).
I'll try to make it simple: I have my PostIt.xib which is composed of 2 labels (which I don't really care about) and also one TextField
and one TextView
. Here is how I tried to get the text from these:
First, in my PostIt.h
:
@interface PostIt : UIView {
IBOutlet UITextField *titre;
IBOutlet UITextView *commentaire; }
Then secondly, in my PostIt.m
: (the real action of this method is that it close a view and normally throw back the information I want to get to another view, here: parent
)
-(IBAction)doubleTap:(UITapGestureRecognizer *)recognizer{
[_parent setTitre:titre.text];
[_parent setCommentaire:commentaire.text];
[_parent setIsEdited:true];
[self removeFromSuperview]; }
My problem here is, when I call a NSLog
(for example) to show me the Strings which are caught (probably a mistake here? sorry) it show me every time : (null)
I have been looking and trying a lot of answer i found but no one seems to be able to solve my problem... If someone could help me it will be really nice, thanks in advance :)
Upvotes: 1
Views: 1894
Reputation:
You should try to input to your code an object part if that's not already done, where you could directly pick up the data that you need and that's also from here that you should update your view.
Upvotes: 1
Reputation: 850
Is there any more code pertaining to the UITextField
?
Based on what I see here you need you first convert the input from the UITextField
into a string
and then you can set the string
where you want.
Updated to add the conversion code,
NSString *stringFromTextField = [yourTextField text];
Here is some more details,
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *yourTextField;
@end
Your Action,
- (IBAction)yourAction:(id)sender {
//Converting UItextfields into strings
NSString *stringFromTextField = [self.yourTextField text];
}
Here is a sample project I made for you on GitHub -
stringFromTextView
Upvotes: 1