当我重复滚动它时,我的TableView崩溃并且它同时包含158个单元格。在每个单元格中,我添加了两个标签,如
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cityLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 190, 20)] autorelease];
cityLabel.tag = kCityLabelTag;
cityLabel.font = [UIFont boldSystemFontOfSize:14];
[cell.contentView addSubview:cityLabel];
nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 22, 300, 20)] autorelease];
nameLabel.tag = kNameLabelTag;
nameLabel.font = [UIFont systemFontOfSize:10];
[cell.contentView addSubview:nameLabel];
} else {
// A reusable cell was available, so we just need to get a reference to the subviews using their tags.
cityLabel = (UILabel *)[cell.contentView viewWithTag:kCityLabelTag];
nameLabel = (UILabel *)[cell.contentView viewWithTag:kNameLabelTag];
}
如果我在功能中释放其中任何一个,那么标签所在的空间会变黑,所以我无法在那里释放标签。但经过一些重型滚动后,它崩溃了。
我该如何解决这个问题?
答案 0 :(得分:0)
好的,我修好了。对不起打扰你们。这是由于我做了一个不必要的解除分配造成的。感谢。