我有這個問題。使用UICollectionView與我的類「myCustomCell」插入我必須更改的標籤。當我使用方法:如何更改我的標籤在customcell中使用「void」didSelectItemAtIndexPath
-(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);
}
}
如何解決?
當你使用void時,你是什麼意思? –
使用此方法,您應該使用didSelectItemAtIndexPath「void」,如下所示: - (Void)CollectionView:(UICollectionView *)CollectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath –