TableView crashes when i scroll it repetitatively and it contains 158 cells at the same time.How can i fix this?
My TableView crashes when i scroll it repetitively and it contains 158 cells loaded at the same time.In each cell, I am adding two more labels like
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 = kNameLabel开发者_如何学PythonTag;
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];
}
If I release any one of them inside the function, that space where label comes go black and so I cant release the labels there. But after some heavy scrolling it crashes.
How can i fix this?
Ok, I fixed it. Sorry to bother u all. It was caused by one of deallocation that i done unwantedly. Thanks.
精彩评论