我有这个问题。将 UICollectionView 与我的类“myCustomCell”一起使用,我在其中插入了一个我必须更改的标签。当我使用该方法时:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = @"Cell";
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
if (indexPath.section == 0) {
cell.backgroundColor = [self colorForIndexToBlack:indexPath.item];
UIColor *colorCell = cell.backgroundColor;
NSString *strColorCell = [NSString stringWithFormat:@"%@", colorCell.hexStringValue];
cell.lblCustomCell.text = [NSString stringWithFormat:@"HEX %@", strColorCell];
} else {
cell.backgroundColor = [self colorForIndexToWhite:indexPath.item];
UIColor *colorCell = cell.backgroundColor;
NSString *strColorCell = [NSString stringWithFormat:@"%@", colorCell.hexStringValue];
cell.lblCustomCell.text = [NSString stringWithFormat:@"HEX %@", strColorCell];
}
return cell;
}
lblCustomCell(这是我要更改的标签)充满了我想要的信息,没关系。但是当我使用这种方法“void”来选择单个单元格并编辑标签的文本时,它不起作用并且不会用我的新文本更改标签。
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = @"Cell";
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
if (indexPath.section == 0) {
cell.backgroundColor = [self colorForIndexToBlack:indexPath.item];
UIColor *colorCell = cell.backgroundColor;
NSString *strColorCell = [NSString stringWithFormat:@"%@", colorCell.hexStringValue];
cell.lblCustomCell.text = strColorCell;
NSLog(@"Indice della cella: %i %i %@", indexPath.item, indexPath.section * 2 + indexPath.row, strColorCell);
} else {
cell.backgroundColor = [self colorForIndexToWhite:indexPath.item];
UIColor *colorCell = cell.backgroundColor;
NSString *strColorCell = [NSString stringWithFormat:@"%@", colorCell.hexStringValue];
cell.lblCustomCell.text = strColorCell;
NSLog(@"Indice della cella: %i %i %@", indexPath.item, indexPath.section * 2 + indexPath.row, strColorCell);
}
}
怎么能修?