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;
}
- (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;
}
相关文章推荐
- IOS开发之----UITableView重用机制
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- UITableView的重用机制(缓存机制)
- 【iOS沉思录】UITableView的重用机制与加载优化详解
- (iphone/ipad)关于uitableview自定义cell与重用机制探究
- 解决UITableView中Cell重用机制导致内容出错的方法总结
- UITableView的重用和注册机制
- UITableView重用机制
- UITableView中Cell重用机制导致内容重复覆盖
- iOS - UITableView中的cell因为重用机制导致新的cell的数据出现重复或者错乱
- UITableView的重用机制
- UITableView的重用机制
- 关于UITableView的重用机制浅谈
- (iphone/ipad)关于uitableview自定义cell与重用机制探究(由于文章写的太好,直接转帖备用)
- ios tableView UITableView中Cell重用机制导致内容重复解决方法
- UITableView的重用机制原理
- iOS学习笔记(4) — UITableView的 重用机制
- UITableView重用机制
- iOS 瀑布流效果(模仿UITableView重用机制)
- UI:UITableView 编辑、cell重用机制