私はUICollectionView
に複数のセルがあり、そこに各セルの色を表すCAGradient
レイヤーが追加されています。問題は、現在のView Controllerの上に別のView Controllerをプッシュしてから、2番目のView Controllerをポップすると、コレクションビューのセルがランダムな順序で色を移動することです。アイデアを伝えるためにスクリーンショットを添付しました。UICollectionViewCellが異常な動作をします。セルが正しくレイヤーを更新しない
これは、セルの元の順序です。これは私が別のビューコントローラをプッシュして、あなたは細胞が、私は何も変わっていないにもかかわらず、その色をシフトしていることがわかります 戻ったときにこれが起こる
正しいです。
これは私がセルを初期化するために使用するコードです。
細胞からの眺めは、私が色を得る方法で、何も悪いことはありません
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
[self filterRecords];
MyCell *cell = (MyCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"ProspectCVCell" forIndexPath:indexPath];
for (int i = 0; i < [eventsSortedForAddedDate count]; i++)
{
Events* event = (Events*)[eventsSortedForAddedDate objectAtIndex:i];
if ([event.activityLevel.activityName isEqualToString:@"None"])
continue;
color = [[event activityLevel] color];
if (![color isEqualToString:@"#FFCCCCCC"])
break;
else
color = nil;
}
if (!([color length] > 0) || color == nil)
{
color = @"#FFCCCCCC";
}
UIColor* myColor = [self getUIColorObjectFromHexString:color alpha:.9];
//cell.backgroundColor = myColor;
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = cell.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[myColor CGColor], (id)[[UIColor whiteColor] CGColor], nil];
gradient.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.85f], nil];
//[cell.layer insertSublayer:gradient atIndex:0];
[cell.layer insertSublayer:gradient atIndex:0];
cell.prospectImageView.layer.shadowColor = [UIColor blackColor].CGColor;
cell.prospectImageView.layer.shadowOffset = CGSizeMake(0, 3.0);
cell.prospectImageView.layer.shadowRadius = 3.0;
cell.prospectImageView.layer.shadowOpacity = 0.8;
cell.cellLabel.text = p.displayName;
cell.layer.borderWidth = 0.5f;
cell.layer.borderColor = [UIColor whiteColor].CGColor;
return cell;
}
、私は複数回をデバッグしていることをチェックして表示されるたびにロードして、[collectionview reloadData]を-viewWillAppearに呼び出されました私が得る色は正しいものです。私は
cell.backgroundColor = myColor;
を行う場合、期待どおり 細胞は、その色や機能を変更しないでください。だから私はかなり問題がCAGradientLayerにあると確信しています。
私は考えることができるすべてを試しましたが、何も動作していないようです!
は場合は '[event.activityLevel.activityName isEqualToString: "なし" @]'あなたは 'continue'いますが、ループ全体' NONE'を取得しない場合は何が起こりますか? – Lion
次に、その下のif条件が実行されます。色はnilになり、私は灰色の陰影であるデフォルトの色を割り当てます。しかし、上記のスクリーンショットからわかるように、それはそうではありません。私は色の値を正しく取得しています。上記のように、cell.backgroundColor = myColorを実行すると、セルは意図したとおりに機能します。この問題は、CAGradientLayerを使用すると発生します。 –
私の答えを試してみてください。 – Lion