Tengo un UITableView con 8 celdas (secciones) en total en las cuales 6 de ellas contienen textFields como subvistas y de 2 que contienen un botón y la otra que contiene texto. Ahora tengo un problema aquí, ya que todos sabemos que cuando la vista aparece solo, las celdas visibles se cargan. Así que cuando mi aplicación se carga, puedo ver 5 celdas, los primeros 4 campos de texto que contienen y la quinta celda con el botón.I puede ver el número de matriz es 4 cuando i exhibidas a través de la tala en la consola es decirCargue todas las celdas en UITableView antes de desplazarse
there are 4 objects in the array
Ahora, después de desplazar la vista de tabla, puedo observar lo siguiente:
there are 6 objects in the array
Entonces, lo que está sucediendo es Si debo guardar los datos ingresados en la vista de tabla, o decir editar para hacer cambios a los datos existentes, me veo obligado a desplazar la vista de tabla e introducir los valores en la última celda también. ese no puede ser el caso siempre con el usuario porque no podemos esperar que se desplace la vista de tabla e ingrese las entradas completas de celda de vista de formulario/tabla. Lo que sea que cambie lo haga y simplemente haga clic en hecho/guarde lo ¡siempre lo es ...!
Más de Tengo una vista del selector como vista de entrada para la última celda que contiene el campo de texto como subvista. Por mi selección seleccioné el método de fila Estoy enfrentando un problema de falla con la última celda/sección (campo de texto como subvista) que contiene Ver selector aquí está mi fragmento de código para el método:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
switch (tagValues)
{
case 105:
{
self.textField = [self.fields objectAtIndex:3];
self.textField.text = [self.reminder objectAtIndex:row];
}
break;
case 107:
{
//Crash occurring in this case,sometimes its working wonder why
self.textField = [self.fields objectAtIndex:5];
self.textField.text = [self.group objectAtIndex:row];
}
break;
}
}
**Note**:I am using the same textField for adding as subview to all 6 cells,but each one with unique tags and own purpose,i.e. one for editing text using key board,one with date picker,one with general picker etc...
me pregunto por qué algunas veces después de seleccionar los valores de la vista selector (última celda de sección) falla algunas veces y algunas veces funciona fine.Some veces se estrella en el anterior línea comentada en caso 107, algunas veces en el grupo de autorrelease principal.Tiempo de tiempo como se muestra en el complemento a continuación:
Entonces, ¿hay alguna manera de que podemos cargar todas las celdas a la vez para que todos los campos de texto se añaden a la matriz antes de scrolling.There no puede haber ningún problema creo
editor de más detallada CÓDIGO para la comprensión:
- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//NSString *identifier = @"UITableViewCell";
NSString *cellIdentifierF = nil;
static NSString *firstCellIdentifier = @"FirstCell";
static NSString *secondCellIdentifier = @"SecondCell";
static NSString *thirdCellIdentifier = @"ThirdCell";
static NSString *fourthCellIdentifier = @"FourthCell";
static NSString *fifthCellIdentifier = @"FifthCell";
static NSString *sixthCellIdentifier = @"SixthCell";
static NSString *seventhCellIdentifier = @"SeventhCell";
static NSString *eightCellIdentifier = @"EightCell";
if(indexPath.section == 0 && indexPath.row == 0)
{
cellIdentifierF = firstCellIdentifier;
}
else if(indexPath.section == 1 && indexPath.row == 0)
{
cellIdentifierF = secondCellIdentifier;
}
else if(indexPath.section == 2 && indexPath.row == 0)
{
cellIdentifierF = thirdCellIdentifier;
}
else if(indexPath.section == 3 && indexPath.row == 0)
{
cellIdentifierF = fourthCellIdentifier;
}
else if(indexPath.section == 4 && indexPath.row == 0)
{
cellIdentifierF = fifthCellIdentifier;
}
else if(indexPath.section == 5 && indexPath.row == 0)
{
cellIdentifierF = sixthCellIdentifier;
}
else if(indexPath.section == 6 && indexPath.row == 0)
{
cellIdentifierF = seventhCellIdentifier;
}
else if(indexPath.section == 7 && indexPath.row == 0)
{
cellIdentifierF = eightCellIdentifier;
}
UITableViewCell *cell = (UITableViewCell *)[atableView dequeueReusableCellWithIdentifier:cellIdentifierF];
atableView.backgroundColor = [UIColor clearColor];
textField = [[[UITextField alloc]initWithFrame:CGRectMake(15, 12, 300, 24)]autorelease];
textField.textColor = [UIColor whiteColor];
textField.delegate = self;
tagValues = textField.tag;
switch (indexPath.section)
{
case 0:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg-1.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: firstCellIdentifier])
{
textField.placeholder = @"Enter name";
[self.textField setValue:[UIColor purpleColor]
forKeyPath:@"_placeholderLabel.textColor"];
textField.tag = 101;
textField.text = reminderInstance.Name;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
NSLog(@"Value = %@",textField.text);
[cell.contentView addSubview:textField];
[self.fields addObject:textField];
}
}
}
break;
case 1:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg-1.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: secondCellIdentifier])
{
textField.tag = 102;
textField.text = reminderInstance.Event;
NSLog(@"Value = %@",textField.text);
[cell.contentView addSubview:textField];
[self.fields addObject:textField];
}
}
}
break;
case 2:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg-1.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: thirdCellIdentifier])
{
textField.placeholder = @"Click here to set date and time";
[self.textField setValue:[UIColor purpleColor]
forKeyPath:@"_placeholderLabel.textColor"];
textField.inputView = self.datePicker;
textField.text = reminderInstance.Date;
textField.tag = 103;
NSLog(@"Value = %@",textField.text);
[cell.contentView addSubview:textField];
[self.fields addObject:textField];
}
}
}
break;
case 3:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg-1.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: fourthCellIdentifier])
{
textField.tag = 105;
textField.text = reminderInstance.numDays;
textField.inputView = self.reminderPicker;
NSLog(@"Value = %@",textField.text);
[cell.contentView addSubview:textField];
[self.fields addObject:textField];
}
}
}
break;
case 4:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg-1.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: fifthCellIdentifier])
{
checkboxButton = [[[UIButton alloc] initWithFrame:CGRectMake(16,1,120, 44)]autorelease];
[checkboxButton setImage:[UIImage imageNamed:@"ewee.png"] forState:UIControlStateNormal];
[checkboxButton addTarget:self action:@selector(toggleButton:) forControlEvents:UIControlEventTouchUpInside];
NSString *one = reminderInstance.selString;
NSNumber* i = [NSNumber numberWithInt:[one intValue]];
BOOL isOn = [i boolValue];
if(isOn)
{
[checkboxButton setImage:[UIImage imageNamed:@"checkarrow.png"] forState:UIControlStateNormal];
}
else
{
[checkboxButton setImage:[UIImage imageNamed:@"ewee.png"] forState:UIControlStateNormal];
}
NSLog(@"String Val = %@",one);
[checkboxButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
[checkboxButton setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)];
[cell addSubview:checkboxButton];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(55, 10, 225, 24)];
label.text = @"Every Year";
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
[cell addSubview:label];
cell.textLabel.textColor = [UIColor whiteColor];
[label release];
}
}
}
break;
case 5:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg-1.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: sixthCellIdentifier])
{
textField.placeholder = @"Enter the number here";
[self.textField setValue:[UIColor purpleColor]
forKeyPath:@"_placeholderLabel.textColor"];
textField.text = num;
textField.text = reminderInstance.number;
textField.tag = 106;
textField.userInteractionEnabled = YES;
textField.keyboardType = UIKeyboardTypeNumberPad;
NSLog(@"Value = %@",textField.text);
[cell.contentView addSubview:textField];
[self.fields addObject:textField];
}
}
}
break;
case 6:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"reminderbuttonxl.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: seventhCellIdentifier])
{
cell.backgroundColor = [UIColor clearColor];
textView.clipsToBounds = YES;
textView = [[UITextView alloc]initWithFrame: CGRectMake(-2, -3, 307, 154)];
UIImageView *imgView = [[[UIImageView alloc]initWithFrame: textView.frame]autorelease];
imgView.image = [UIImage imageNamed: @"buttonbg_text.png"];
[textView addSubview: imgView];
[textView sendSubviewToBack: imgView];
textView.backgroundColor = [UIColor clearColor];
textView.delegate = self;
textView.tag = 11;
tagValues = textView.tag;
textView.textColor = [UIColor purpleColor];
[cell.contentView addSubview:textView];
textView.text = @"Your birthday wishes/other reminder body here";
NSLog(@"Value = %@",textView.text);
}
}
}
break;
case 7:
{
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifierF] autorelease];
cell.backgroundColor = [[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"buttonbg-1.png"]];
//Only add content to cell if it is new
if([cellIdentifierF isEqualToString: eightCellIdentifier])
{
textField.tag = 107;
textField.inputView = self.groupPicker;
tagValues = textField.tag;
textField.text = reminderInstance.remGroup;
NSLog(@"Value = %@",textField.text);
[cell.contentView addSubview:textField];
[self.fields addObject:textField];
}
}
}
break;
default:
break;
}
int size = [fields count];
NSLog(@"there are %d objects in the array", size);
return cell;
}
yo he hecho varios intentos para averiguar lo que está pasando exactamente equivocado también comprobé algunas preguntas here y there .Pero no pude encontrar ninguna effic ient/appr. responder o eso resuelve mi problema.
Así que cualquier persona por favor ayúdame con sugerencias valiosas o ejemplos de fragmentos de código.
Gracias a todos de antemano :)
No creo que sea posible cargar celdas que no son visibles. La tabla extraerá datos de la fuente de datos y solo cargará las celdas visibles.Las otras celdas se cargarán mientras se desplaza y se volverán visibles. –
donde estás haciendo una nueva celda si no existe – fibnochi
@BillBurgess Gracias Sr. Burgess que yo sepa también sabía lo que dijiste ... pero estoy enfrentando muchos problemas debido a esto porque sin hacer ningún cambio o tocar el último Después de desplazarme, no puedo actualizar datos también sin hacerlo. Indique también si el usuario ingresa a la vista de tabla, rellenada con los datos ingresados en ese momento. Luego, diga si el usuario modifica casualmente las primeras 2 celdas y hace clic. Luego, considera los últimos valores de campo (invisibles) como nulos aunque haya valores. –