您的位置:首页 > 产品设计 > UI/UE

UItableView的重用机制

2012-05-11 22:51 796 查看
在UITableViewCell上添加SubView后,点击状态(高亮)时,出现重叠现象,原来是UItableView的重用机制问题,解决方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

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

}

NSArray
*subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];

for (UIView *subview in subviews) {

[subview removeFromSuperview];

}

[subviews release];

/*或者

for (UIView *view in [cell subviews]){

[view removeFromSuperview];

}

*/

/*或者

for (UIView *viewToRemove in [cell.contentView subviews]){

[viewToRemove removeFromSuperview];

}

*/

//customer

return cell;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: