ios xcode4 deprecated reuseidentifier

ios - initWithFrame: reuseIdentifier: está en desuso



xcode4 deprecated (4)

Este problema aparece en Beginning IOS 5 Development por Mark, Nutting y La Marche. Algunos lectores pueden venir del libro donde aparece el código desaprobado en la página 265. ¡Pueden asumir que la culpa es de ellos!

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: sectionsTableIdentifier] autorelease];

necesita ser reemplazado por (como los contribuyentes arriba señalan)

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: sectionsTableIdentifier];

Tenga en cuenta que también he eliminado el autorelease porque el conteo automático de referencias no me gusta.

Espero que esto ayude.

En mi proyecto tengo una advertencia de desaprobaciones, initWithFrame: reuseIdentifier: está en desuso

No sé qué significa, alguien podría decirme cómo resolver esta advertencia, gracias.

Aquí está el código corto

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } // Set up the cell... NSString *cellValue = [itemsList objectAtIndex:indexPath.row]; cell.textLabel.text = cellValue; return cell; }

y la advertencia está en esa línea:

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];


Esto debería solucionar tu problema:

static NSString *SimpleTableIdentifier; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SimpleTableIdentifier] autorelease]; }


Usa este código:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];


Echa un vistazo a esta página de Apple

Aquí, las funciones y propiedades resaltadas en rojo serán eliminadas en el futuro por Apple en el próximo SDK.

para que podamos evitarlos al crear la aplicación.

Porque necesitamos un proyecto a largo plazo que debería ejecutarse sin fallas.

un método en desuso significa que ha sido reemplazado / retirado pero aún es válido en la versión actual del idioma. Debe evitarse y puede causar problemas / errores. verifique la documentación que debería incluir un método alternativo que pueda usar.

Aquí deberías usar el método

- initWithStyle:reuseIdentifier:

Entonces tu ciclo if se vería así

if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }