原文轉載自:http://blog.csdn.net/beijinuo/article/details/8264979
在IOS開發的時候經常會用到UITableView,而當TableView進行拖動的時候經常會導緻Cell的重疊,現在記錄下自己經常使用的解決方法,
以免以後再到處找
1.
[java] view plain copy
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"ToneBoxMusicStyleViewCell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"ToneBoxMusicStyleViewCell" owner:self options:nil];
- if ([nib count] > 0) {
- cell = self.styleViewCell;
- }
- }else{
- for (UIView *subView in cell.contentView.subviews)
- {
- [subView removeFromSuperview];
- }
- }
- return cell;
- }
2.
[java] view plain copy
- //建構tableView
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"TodoViewController"];
- cell.tag = 1;
- if(!cell){
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TodoViewController"]autorelease];
- }else{
- while ([cell.contentView.subviews lastObject] != nil) {
- [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
- }
- }