hii every one
i have created a data entry screen like this in which each row contains a text field
here after entering data into the text field if we scroll the page which are all the text fields goesup(beyond the view) will set to null when it come back to the original position,, this is my code for each cell where CustomCellStudentData is a cell class where i have created frames for lables
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//static NSString *CellIdentifier = @"Cell";
CustomCellStudentData *cell = (CustomCellStudentData*)[tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
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,22, 170, 25)];
cell.accessoryView = tfText[0];
tfText[0].delegate=self;
tfText[0].font = [UIFont systemFontOfSize:14];
tfText[0].placeholder =@"<Student Name>";
cell.primaryLabel.text =@"Student Name: ";
}
break;
case 1:
{
tfText[1] = [[UITextField alloc] initWithFrame:CGRectMake(125,22, 170, 25)];
cell.accessoryView = tfText[1];
tfText[1].delegate=self;
tfText[1].font = [UIFont systemFontOfSize:14];
tfText[1].placeholder =@"<Student Age>";
tfText[1].keyboardType = UIKeyboardTypeNumbersAndPunctuation;
cell.primaryLabel.text =@"Student Age: ";
}
break;
case 2:
{
cell.primaryLabel.text =@"Gender: ";
segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.frame = CGRectMake(125,22, 170, 25);
[segmentedControl insertSegmentWithTitle:@"Male" atIndex:0 animated:YES];
[segmentedControl insertSegmentWithTitle:@"Female" atIndex:1 animated:YES];
segmentedControl.selectedSegmentIndex = 1;
[segmentedControl setMomentary:NO];
[segmentedControl addTarget:self action:@selector(segmentSwitch:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView =segmentedControl;
}
break;
case 3:
{
tfText[3] = [[UITextField alloc] initWithFrame:CGRectMake(125,22, 170, 25)];
cell.accessoryView = tfText[3];
tfText[3].delegate=self;
tfText[3].font = [UIFont systemFontOfSize:14];
tfText[3].placeholder =@"<dd/mm/yyyy>";
tfText[3].keyboardType = UIKeyboardTypeNumbersAndPunctuation;
cell.primaryLabel.text =@"Date Of Birth: ";
}
}
}
y that data becoming null, how can i resolve this ,, can any one help me,,
thanx in advance
You are creating the text fields every time
cellForRowAtIndexPath:is called. I think you can solve this problem by creating the text fields elsewhere, probably inviewDidLoador similar method and just set the accessory view when thecellForRowAtIndexPath:is called. For example,Move the top four lines to
viewDidLoadand create them only once. And let the line below remain as it is.