Pour définir cell.textLabel.text dans la méthode cellForRowAtIndexPath, j'alloue et init une chaîne. Si je libère cette chaîne après avoir défini cell.textLabel.text, alors le programme va se bloquer après avoir fait cela plusieurs fois.NSString n'a pas besoin d'être libéré dans cellForRowAtIndexPath: méthode?
Pourquoi ne plante-t-il pas la première fois? Puisque la chaîne a été allouée et initialisée, ne doit-elle pas être libérée?
Voici le code:
NSString *cellText = [[NSString alloc] init];
cellText = [NSString stringWithFormat:@"(%.1f points", totalpoints];
if (showNumberOfPlayers) {
cellText = [cellText stringByAppendingFormat:@", %i players) ", [[playerArray objectAtIndex:indexPath.row] count]];
}
else {
cellText = [cellText stringByAppendingString:@") "];
}
cell.textLabel.text = [cellText stringByAppendingString:teamList];
[cellText release];
Afficher le code – willcodejavaforfood