views:

26

answers:

0

I am saving the text field value when Next button clicked on the key board, Instead selecting next cell or scrolling the table view the content of the text fields are disappeared because I am not saving the data in the object.It will save only when we select Next button in the Keyboard.

I want to save the data while typing in the test field, Is there any method or process to save data while typing. please give response. I am thankful to you.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell *)[myTableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];

        UIView* elementView =  [ [UIView alloc] initWithFrame:CGRectMake(5,5,300,480)];
        elementView.tag = 0;
        [cell.contentView addSubview:elementView];
        [elementView release];
    }
    UIView* elementView  = [cell.contentView viewWithTag:0];
    for(UIView* subView in elementView.subviews)
    {
        [subView removeFromSuperview];
    }
if(indexPath.section == 0)
        {
            UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
            headerLabel.frame = CGRectMake(10,10,50,20);
            headerLabel.backgroundColor = [UIColor clearColor];
            headerLabel.textColor = [UIColor colorWithRed:0.19 green:0.08 blue:0.05  alpha:1];
            headerLabel.highlightedTextColor = [UIColor whiteColor];
            headerLabel.font = [UIFont systemFontOfSize:15];
            headerLabel.text = @"Name :" ;// i.e. array element
            [elementView addSubview:headerLabel];
            [headerLabel release];


            NameField=[[UITextField alloc]initWithFrame:CGRectMake(65,10,230,30)];
            NameField.textColor = [UIColor blackColor];
            NameField.font = [UIFont systemFontOfSize:15.0];

            NameField.backgroundColor = [UIColor clearColor];
            //firstNameField.enabled=NO;
            //firstNameField.userInteractionEnabled=NO;
            NameField.returnKeyType=UIReturnKeyNext;
            NameField.keyboardType = UIKeyboardTypeDefault;
            NameField.clearButtonMode = UITextFieldViewModeWhileEditing;    // has a clear 'x' button to the right
            NameField.leftViewMode = UITextFieldViewModeAlways;
            //NameField.textAlignment=UITextAlignmentRight;
            NameField.delegate = self;

            if([myObject.firstName length]>0)
            {
                NameField.text= myObject.firstName;
            }
            else
            {
                NameField.placeholder = @"Enter Name ";
            }

            NameField.placeholder = @"Enter Name ";
            [elementView addSubview:NameField];
            [NameField release];

        }
        if(indexPath.section == 1)
        {


            UILabel * headerLabel1 = [[UILabel alloc] initWithFrame:CGRectZero];
            headerLabel1.frame = CGRectMake(10,10,85,20);
            headerLabel1.backgroundColor = [UIColor clearColor];
            headerLabel1.opaque = NO;
            headerLabel1.textColor = [UIColor colorWithRed:0.19 green:0.08 blue:0.05  alpha:1];
            headerLabel1.highlightedTextColor = [UIColor whiteColor];
            headerLabel1.font = [UIFont systemFontOfSize:15];
            headerLabel1.text = @"Credential :" ;// i.e. array element
            [elementView addSubview:headerLabel1];
            [headerLabel1 release];

            credentialField=[[UITextField alloc]initWithFrame:CGRectMake(95,10,210,30)];
            credentialField.textColor = [UIColor blackColor];
            credentialField.font = [UIFont systemFontOfSize:15.0];

            credentialField.backgroundColor = [UIColor clearColor];
            //firstNameField.enabled=NO;
            //firstNameField.userInteractionEnabled=NO;
            credentialField.returnKeyType=UIReturnKeyNext;
            credentialField.keyboardType = UIKeyboardTypeDefault;
            credentialField.clearButtonMode = UITextFieldViewModeWhileEditing;  // has a clear 'x' button to the right
            credentialField.leftViewMode = UITextFieldViewModeAlways;
            credentialField.delegate = self;
            if([myObject.credential length]>0)
            {
                credentialField.text= myObject.credential;
            }
            else
            {
                credentialField.placeholder = @"Enter Credential ";
            }

            credentialField.placeholder = @"Enter Credential ";
            [elementView addSubview:credentialField];
            [credentialField release];
        }
        if(indexPath.section == 2)
        {
            UILabel * headerLabel2 = [[UILabel alloc] initWithFrame:CGRectZero];
            headerLabel2.frame = CGRectMake(10,10,80,20);
            headerLabel2.backgroundColor = [UIColor clearColor];
            headerLabel2.opaque = NO;
            headerLabel2.textColor = [UIColor colorWithRed:0.19 green:0.08 blue:0.05 alpha:1];
            headerLabel2.highlightedTextColor = [UIColor whiteColor];
            headerLabel2.font = [UIFont systemFontOfSize:15];
            headerLabel2.text = @"Speciality :" ;// i.e. array element
            [elementView addSubview:headerLabel2];
            [headerLabel2 release];

            specialityField=[[UITextField alloc]initWithFrame:CGRectMake(95,10,210,30)];
            specialityField.textColor = [UIColor blackColor];
            specialityField.font = [UIFont systemFontOfSize:15.0];

            specialityField.backgroundColor = [UIColor clearColor];
            //firstNameField.enabled=NO;
            //firstNameField.userInteractionEnabled=NO;
            specialityField.returnKeyType=UIReturnKeyNext;
            specialityField.keyboardType = UIKeyboardTypeDefault;
            specialityField.clearButtonMode = UITextFieldViewModeWhileEditing;  // has a clear 'x' button to the right
            specialityField.leftViewMode = UITextFieldViewModeAlways;
            specialityField.delegate = self;
            if([myObject.speciality length]>0)
            {
                specialityField.text= myObject.speciality;
            }
            else
            {
                specialityField.placeholder = @"Enter Speciality ";
            }
            specialityField.placeholder = @"Enter Speciality ";
            [elementView addSubview:specialityField];
            [specialityField release];


        }
return cell;    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    printf("\n I am in textFieldShouldReturn method");
    if(isAdd==YES)
    {       
        if(textField == NameField)
        {
            myObject.firstName=NameField.text;
            [credentialField becomeFirstResponder];
            [textField resignFirstResponder];

        }


        else if(textField == credentialField)
        {
            myObject.credential=credentialField.text;
            [specialityField becomeFirstResponder];
            [textField resignFirstResponder];
        }
        else if(textField == specialityField)
        {
            myObject.speciality=specialityField.text;
            [streetField becomeFirstResponder];
            //[self setViewMovedUp:NO];
            [textField resignFirstResponder];
        }
}