UITableViewCell重叠

来源:互联网 发布:乐心手环数据清零几点 编辑:程序博客网 时间:2024/04/28 12:29

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

以免以后再到处找

1.

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

2.

[java] view plaincopy
  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.           
  9.     }else{  
  10.         while ([cell.contentView.subviews lastObject] != nil) {  
  11.             [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];  
  12.         }  
  13.     }  
0 0
原创粉丝点击