这个方法就是给每一个cell一个唯一的标识符,正常情况下重用cell,给cell的一些子视图赋值时不会发生cell重用混乱问题,但是在修改cell子视图的属性的时候就会发生cell复用的混乱。下面是代码片段
-
- NSString *identifier = [_cellDic objectForKey:[NSString stringWithFormat:@"%@", indexPath]];
-
- if (identifier == nil) {
- identifier = [NSString stringWithFormat:@"KeyboardTextCell%@", [NSString stringWithFormat:@"%@", indexPath]];
- [_cellDic setValue:identifier forKey:[NSString stringWithFormat:@"%@", indexPath]];
-
- [self.keyboardView registerClass:[KeyboardTextCell class] forCellWithReuseIdentifier:identifier];
- }
-
- KeyboardTextCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
-
- cell.textLab.text = self.characterArr[indexPath.row];
- return cell;