Objective C でアプリを作成しています。コレクション ビューにカスタム セルがあります。最初に、SQLite Db からデータをロードし、各カスタム セル内のコレクション ビューに表示します。コレクションビューにセルを表示します。
コレクション ビューをリロードすると、コレクション ビューは黒色のままになります。
コード:
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 3;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self readRowCount:@"SELECT COUNT(label) FROM colour;"];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%d", [arrColour count]);
CustomViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ItemCell" forIndexPath:indexPath];
// if (cell == nil) {
// cell = [[CustomViewCell alloc]init];
//}
cell.label.text = [NSString stringWithFormat:@"%@",[ [arrColour objectAtIndex:indexPath.item ]label] ];
CellData *redObj = [arrColour objectAtIndex:indexPath.row];
CellData *greenObj = [arrColour objectAtIndex:indexPath.row];
CellData *blueObj = [arrColour objectAtIndex:indexPath.row];
float redF = [[redObj red] floatValue];
float greenF = [[greenObj green] floatValue];
float blueF = [[blueObj blue] floatValue];
//NSLog(@"Colours: %f-%f-%f", redF, greenF, blueF);
cell.backgroundColor = [UIColor colorWithRed:redF/255.0f green:greenF/255.0f blue:blueF/255.0f alpha:1];
return cell;
}
データをリロードする場所 - ボタン:
- (IBAction)btnAdd:(id)sender {
NSString *myRed = [NSString stringWithFormat: @"%1.4f", slideR.value];
NSString *myGreen = [NSString stringWithFormat: @"%1.4f", slideG.value];
NSString *myBlue = [NSString stringWithFormat: @"%1.4f", slideB.value];
if(txtField != nil){
[colMain reloadData];
}
この状況の arrColour (可変配列) には、同じ量の要素が含まれます。コレクション ビューがリロードされていないのは何ですか?