天天看点

避免UITableViewCell重叠的解决方法

原文转载自:http://blog.csdn.net/beijinuo/article/details/8264979

在IOS开发的时候经常会用到UITableView,而当TableView进行拖动的时候经常会导致Cell的重叠,现在记录下自己经常使用的解决方法,

以免以后再到处找

1.

[java]  view plain copy

  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
  2.     static NSString *CellIdentifier = @"ToneBoxMusicStyleViewCell";  
  3.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
  4.     if (cell == nil) {  
  5.         NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"ToneBoxMusicStyleViewCell" owner:self options:nil];  
  6.         if ([nib count] > 0) {  
  7.             cell = self.styleViewCell;  
  8.         }  
  9.     }else{  
  10.         for (UIView *subView in cell.contentView.subviews)  
  11.         {  
  12.             [subView removeFromSuperview];  
  13.         }  
  14.     }  
  15.     return cell;  
  16. }  

2.

[java]  view plain copy

  1. //构建tableView  
  2. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  3. {  
  4.     UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"TodoViewController"];  
  5.     cell.tag = 1;  
  6.     if(!cell){  
  7.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TodoViewController"]autorelease];          
  8.     }else{  
  9.         while ([cell.contentView.subviews lastObject] != nil) {  
  10.             [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];  
  11.         }  
  12.     }