What is the proper way to define a user input variable so it maintains its value after control is returned to the user. I have a TextView where the user enter a description, and I want to clear the contents of the TextView but maintain what the user first ent开发者_如何学JAVAered.
Define a NSString in the header of your UIViewController, make your UIViewController a UITextViewDelegate (@interface MyViewController : UIViewController{ ), and set your UITextView's delegate property to self. Then, in your -(void)textViewDidChangeSelection:(UITextView *)textView
method, set the NSString variable to your UITextView's text. When the user removes the focus from your UITextView, you clear its contents, and the NSString variable will have been left with the text that was typed in before clearing.
精彩评论