开发者

Retaining state of a user variable in Cocoa

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜