1
爲了在cellForRowAtIndexPath方法中設置cell.textLabel.text,我分配並初始化一個字符串。如果我在設置cell.textLabel.text後釋放這個字符串,那麼程序會在執行幾次後崩潰。NSString不必在cellForRowAtIndexPath:方法中被釋放?
爲什麼不第一次崩潰?既然這個字符串是被分配和編輯的,是不是必須被釋放?
下面的代碼:
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];
請給出代碼 – willcodejavaforfood 2010-10-10 12:58:43