保留NSString中文本框的值

时间:2011-08-15 09:02:05

标签: iphone objective-c ios memory-management

这是我的.h文件:

我遇到问题的IBOutlet是文本框。我想将文本框中的值保留为NSString:

@interface UploaderViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
    IBOutlet UIImageView *imageView;
    IBOutlet UITextField *textCaption;
    NSString *caption;
}

- (IBAction)pushPick;
- (IBAction)pushUpload;
@property (nonatomic, retain) IBOutlet UITextField *textCaption;

@end

值存储在此NSString中:

- (IBAction)pushUpload {
    caption = textCaption.text;
}

2 个答案:

答案 0 :(得分:1)

我认为你打算做这样的事情:

- (IBAction)pushUpload {
    [caption release];
    caption = [textCaption.text copy];
}

答案 1 :(得分:0)

在shouldChangeTextInRange中调用你的pushUpload。