开发者

iPhone UItextfield entry saving method

开发者 https://www.devze.com 2023-02-20 07:36 出处:网络
Just ran into UXproblem to save UITextField input value.I\'ve got 6 UItextfield entries which saves individual value in sqlite db.

Just ran into UX problem to save UITextField input value.I've got 6 UItextfield entries which saves individual value in sqlite db.

Right now each field has separate save button.So six ones quite look messy and silly. I just want to know if there is any method to save entry after开发者_JS百科 editing ends.

To be more concise...

I want to save data in UITextField after user ends editing.Just needs 'Saving Logic' for problem


You probably want to use an object which implements UITextFieldDelegate protocol. It defines –textFieldShouldEndEditing: and –textFieldDidEndEditing: methods which are called just before and once text editing ends.

Your delegate should be declared like:

@interface ATextFieldDelegate : NSObject<UITextFieldDelegate>
{
}
@end

And implements the methods:

@implementation ATextFieldDelegate
- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
    // Test if the textField.text is valid for storage
    // Return YES if it is, NO if not
}

- (void) textFieldDidEndEditing:(UITextField *)textField
{
    // Store textField.text into your SQLite database
}
@end

And you should set your UITextField's delegate:

UITextField *myTextField; // could be an IBOutlet
ATextFieldDelegate *myTextFieldDelegate; // must be initialized somewhere
myTextField.delegate = myTextFieldDelegate;
0

精彩评论

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

关注公众号