Hii everyone!
I have some text fields in each cell of the table view, like this

If I enter some data into the text field and scroll the view up and down again, the data in the text field is set to null. Why does this happen, how can I avoid this?
Following is my code for cell construction
static NSString *CellIdentifier = @"Cell";
CustomCellStudentData *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// cell = [[[CustomCellStudentData alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell = [[[CustomCellStudentData alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
switch(indexPath.section)
{
case 0:
switch (indexPath.row)
{
case 0:
{
tfText[0] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)];
cell.accessoryView = tfText[0];
tfText[0].delegate = self;
tfText[0].text = @"";
tfText[0].placeholder = @"<Student Name>";
cell.primaryLabel.text = @"Student Name: ";
}
break;
case 1:
{
tfText[1] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)];
cell.accessoryView = tfText[1];
tfText[1].delegate=self;
tfText[1].placeholder = @"<Student Age>";
cell.primaryLabel.text = @"Student Age: ";
}
break;
}
Thanx in advance
when the cell is scrolled out of window, it may be released, so you must save the input in somewhere and read from there in cell construction method.
Take one cell with one textfield as example:
first I declare a NSString in my interface,and apply to UITextFieldDelegate protocol:
then, in cellForRowAtIndex:
At last, apply this to update contentOfTextField everytime you edit it: