jftuga jftuga - 4 months ago 38
Objective-C Question

connect IBOutlet to textViewDidEndEditing

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
delegate. How can I get this method called once the user stops editing the note?


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];