0

I have a UITextView:

@property (nonatomic, weak) IBOutlet UITextView *notesTv;

This was created by ctrl-dragging from the Main.storyboard to my .m file. This is field will be used by the user to add a note. My goal is to save the contents to NSUSerDefaults without having a save button. I have used NSUserDefaults before so that is not the issue.

I want to use UITextViewDelegate's textViewDidEndEditing delegate method to save user input once they are done typing in a note.

When I ctrl-click on the UITextView in storyboard, I don't see a way to connect this to the textViewDidEndEditing delegate. How can I get this method called once the user stops editing the note?

jftuga
  • 1,913
  • 5
  • 26
  • 49

1 Answers1

1

set delegate programmatically for same class

notesTv.delegate=self; and for other class
iOS - Setting delegate of input stream to another class

and then write this code in textViewDidEndEditing:

  NSString *valueToSave = self.notesTv.text;
    [[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"preferenceName"];
    [[NSUserDefaults standardUserDefaults] synchronize];
Community
  • 1
  • 1
Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38