Reputation: 149
I have a view that through a prepareSeque method should pass whatever is written in a textView to the next view. Before I had textField and textfield.text in the seque method worked fine. But I can not get it to work with a textView.
I have a NSString property in the .h file: @property (weak, nonatomic) NSString *textString; I syntesize it in the .m file: @synthesize textString =_textString;
In my textViewDidEndEditing i can see (through debug) that the text in the text View is picked up and that the textString is set.
However, when I then want to retrieve the textString in my Seque method it does not contain any text:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"go"]) {
ISecondViewController *vc = [segue destinationViewController];
vc.funnyString = self.textString;
}
If i enter: self.textString =@"Hi Hi"; in the Seque method funnyString will be passed with Hi Hi so that part works fine.
Have I just totally misunderstood the "get and set" of NSString in this case?
Upvotes: 0
Views: 151
Reputation: 11537
Your problem here is that you have been using a weak
property for textString
so it will be nil
when the scope of your property get out of your textViewDidEndEditing
method.
Why? because the principle of weak reference is that it will be set to nil
as soon as the object you are referring to doesn't exist anymore. This will be the case for the "theText
" object which won't exist at the end of your method. Use a strong
property instead.
Upvotes: 2