/ / Almacenar valor booleano en UITableviewcell - iphone, ios, uitableview, booleano

Almacene el valor booleano en UITableviewcell - iphone, ios, uitableview, boolean

¿Cómo puedo almacenar un valor booleano en cada fila de una vista de UITable? Necesito recuperar el valor booleano almacenado en la celda, cuando se selecciona esa celda en particular.

Respuestas

1 para la respuesta № 1

Recomiendo usar propiedad de etiqueta en UITableViewCell.

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
// returns nil if cell is not visible or index path is out of range
{

static NSString *identifier = @"MyIndetifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:CellIdentifier] autorelease];
}
//make sure tu put here, or before return cell.
cell.tag = 0; //0 =NO, 1=YES;

return cell;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
BOOL boolean = cell.tag; // return 0 or 1. based on what boolean you set on this particular row.
}

2 para la respuesta № 2

Hay tantas maneras:
1. Puedes usar la propiedad UITableViewCell.tag
2. Puede crear su propia clase de célula heredada de UITableViewCell y agregar allí la propiedad normal para su valor BOOL
3. Puede usar la matriz asociada con su vista de tabla y cuando seleccione la celda, simplemente use indexPath para encontrar el valor asociado en su matriz
etc.


0 para la respuesta № 3

Probablemente tengas algún otro almacenamiento, dondemantener cosas como el título de celda de la tabla o subtítulo. Guarde el booleano allí. Use esto para convertir el bool en algo que pueda poner en una matriz o diccionario.

[NSNumber numberWithBool:YES]

Por ejemplo, si está utilizando un NSArray de cadenas para almacenar los títulos, en su lugar use una variedad de diccionarios. Cada diccionario tendría un "título" y (por ejemplo) "es activo" booleano (almacenado como un NSNumber)


0 para la respuesta № 4

NSMutableArray * tableData;

cada celda de tabla asociada con un almacén NSMutableDictionary en tableData, puede establecer un NSNumber (store bool) en el Diccionario.


0 para la respuesta № 5

Necesitas implementar el método de UITableView.

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
// returns nil if cell is not visible or index path is out of range
{
//create cell here
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
  • (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath { // utilizando indexpath.row puede acceder a la celda en la que el usuario hizo clic. }