我正在用 Objective C 编写一个应用程序。我在集合视图中有自定义单元格。最初,它从 SQLite Db 加载数据并将其显示在每个自定义单元格内的 Collection 视图中。它在集合视图上显示单元格。
一旦我重新加载集合视图,集合视图将保持黑色。
代码:
-(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(可变数组)包含相同数量的元素。什么集合视图没有重新加载?