如何保存自定义单元格文本字段的数据?

问题描述:

我是iPhone开发的新手,我正在开发一个应用程序,如果我具有带自定义单元格的tableview,我的自定义单元格包含label和textfiled.这是我的注册屏幕,如何保存我的文本字段的数据,以及如何对文本进行验证.在文本字段endediting中,我们可以保存数据.但是如果第一个提交的用户输入名称,然后他单击完成按钮,它将显示请输入名字,因为我在didendediting中保存数据.我想在用户在文本字段上时保存数据.

i am new to the iPhone development, i am developing an app were i have tableview with custom-cell,my custom-cell contains label and textfiled. this is my registration screen,How to save the data of my textfields and,how to do validations for the text. In the textfield endediting we can save the data. but if the user on the first filed enter name and then he click done button it will show please enter first name, because i am saving data in didendediting. i want to save the data when ever user is on the textfield.

您可以使用此方法在模型类对象的帮助下跟踪当前的文本字段文本.

you can use this method to trace your current textfield text, with the help of the model class objects to store your text.

- (BOOL)textField:(UITextField *)theTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString *characterSet = nil; 
    switch (theTextField.tag) 
    {
        case 1:
            characterSet = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
            [sharedInstance.registrationDetails setFirstName:theTextField.text];


            default:
            characterSet = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789?/!@#$&*.,-:; _";
            break;
    }
    NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:characterSet];
    for (int i = 0; i < [string length]; i++)
    {
        unichar c = [string characterAtIndex:i];
        if (![myCharSet characterIsMember:c]) 
        {
            return NO;
        }
    }
    return YES;
}