当我们滚动UITableView时,有时cell会重合起来,很难看,下面是两种解决方法:
方法1:
- - (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;
- }
方法二:移除原先所有控件
- //构建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];
- }
- }
注:如果要在选中某行后马上去掉选中状态,使用如下方法:
// 取消选中状态
[tableView deselectRowAtIndexPath:indexPath animated:NO];