Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView重新加载数据不';我不能正常工作_Ios_Objective C_Uicollectionview_Reloaddata - Fatal编程技术网

Ios UICollectionView重新加载数据不';我不能正常工作

Ios UICollectionView重新加载数据不';我不能正常工作,ios,objective-c,uicollectionview,reloaddata,Ios,Objective C,Uicollectionview,Reloaddata,我面临一个奇怪的问题,当我从一个操作(按钮)执行UICollectionView的重新加载数据时,单元格没有正确显示,只有单元格的背景图像正常 我的“INVPropertyCell”由一个背景图像和两个标签(标题和价格)组成。当我执行重新加载数据时,单元格中的上述标签随机消失 我在不同的论坛上做了很多搜索,有些人有同样的问题,但我没有找到解决办法 下面,您将找到我的代码,如果有人能帮助我,将非常感谢 杰罗姆 - (void)viewDidLoad { NSLog (@"INVProper

我面临一个奇怪的问题,当我从一个操作(按钮)执行UICollectionView的重新加载数据时,单元格没有正确显示,只有单元格的背景图像正常

我的“INVPropertyCell”由一个背景图像和两个标签(标题和价格)组成。当我执行重新加载数据时,单元格中的上述标签随机消失

我在不同的论坛上做了很多搜索,有些人有同样的问题,但我没有找到解决办法

下面,您将找到我的代码,如果有人能帮助我,将非常感谢

杰罗姆

- (void)viewDidLoad
{
    NSLog (@"INVPropertiesViewController -- viewDidLoad");


    [super viewDidLoad];

    // Enregistrement de la cellule.
    [self.clProperties registerNib:[UINib nibWithNibName:@"INVPropertyCell" bundle:nil] forCellWithReuseIdentifier:@"propertyCell"];

    // Enregistrement du header de section
    [self.clProperties registerNib:[UINib nibWithNibName:@"INVPropertyHeaderSection" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerCollectionCell" ];


    self.clProperties.delegate = self;
    self.clProperties.dataSource =self;


    NSLog (@"INVPropertiesViewController -- End of viewDidLoad");
}

- (void)viewWillAppear:(BOOL)animated
{
    NSLog (@"INVPropertiesViewController -- viewWillAppear");

    [super viewWillAppear:animated];

    categoryDictionary = [ServiceDatas getCategoriesDictionary];
    tblProperties = [(NSArray*)[ServiceDatas getListPropertiesByLieuFromLocalDataStore:self.selectedResidence] mutableCopy];

    if(tblProperties.count==0 & self.selectedResidence.propertiesCount.longValue >0)
        tblProperties = [(NSArray*)[ServiceDatas getListPropertiesByLieuFromServer:self.selectedResidence] mutableCopy];

    tblPropertiesByCategory = [ServiceDatas createCategoryBreakDown:tblProperties];

    keysCategories = [tblPropertiesByCategory allKeys];


    [self.clProperties reloadData];


    NSLog (@"INVPropertiesViewController -- End of viewWillAppear");
}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
   // [self.clProperties.collectionViewLayout invalidateLayout];
    return tblPropertiesByCategory.count;
}

- (UICollectionReusableView *)collectionView: (UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{

    UICollectionReusableView *reusableview = nil;

    if(kind == UICollectionElementKindSectionHeader){


        INVPropertyHeaderSection *headerSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerCollectionCell" forIndexPath:indexPath];

        id categoryId = [keysCategories objectAtIndex:indexPath.section];

        CategoryModel *category = categoryDictionary[categoryId];

        if(category!=nil){

            headerSection.backgroundColor = [Utils colorFromHexString:category.color];
            headerSection.lblCategory.text = [category.title uppercaseString];

        }


        reusableview = headerSection;


    }else if(kind == UICollectionElementKindSectionFooter){

        if (reusableview==nil) {
            reusableview=[[UICollectionReusableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        }

    }

    return reusableview;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    // Return the number of rows in the section.

    id categoryId = [keysCategories objectAtIndex:section];
    NSMutableArray *tblProperties = [tblPropertiesByCategory objectForKey:categoryId];


    return [tblProperties count];

}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    INVPropertyCell *cell = nil;

    id categoryId = [keysCategories objectAtIndex:indexPath.section];

    NSMutableArray *tblProperties = [tblPropertiesByCategory objectForKey:categoryId];


    if(tblProperties!=nil){

        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"propertyCell" forIndexPath:indexPath];

        PropertyModel *property = [tblProperties objectAtIndex:indexPath.item];

        NSLog(@"Ligne %ld - Colonne %ld - Lieux %@",indexPath.section, (long)indexPath.item, property.title );

        CategoryModel *category = categoryDictionary[categoryId];

        if(category!=nil){

            [cell initWithProperty:property backgroundColor:[Utils colorFromHexString:category.color]];

        }


    }


    return cell;

}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    // Récupération du bien courant.
    id categoryId = [keysCategories objectAtIndex:indexPath.section];

    NSMutableArray *tblProperties = [tblPropertiesByCategory objectForKey:categoryId];

    PropertyModel *property = [tblProperties objectAtIndex:indexPath.row];

    NSLog(@"Property sélectionnée : %@",property.title);

    self.selectedProperty = property;

    if(property!=nil && [property.title isEqualToString:EMPTY_PROPERTY]){
        self.selectedProperty = nil;
    }

    // Déclenche le Segue pour aller à l'écran "Property"
    [self performSegueWithIdentifier:@"segueEditPropertyView" sender:self];

}

// Layout: Set cell size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGSize mElementSize = CGSizeMake(107, 106);

    if(indexPath.item==0){
        mElementSize = CGSizeMake(106, 106);
    }

    return mElementSize;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0.0;
}

// Layout: Set Edges
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0,0,0,0);  // top, left, bottom, right
}

- (IBAction)btnRefresh:(id)sender {

    [self.clProperties reloadData];

}

我认为,在为INVPropertyCell和INVPropertyHeaderSection单元格注册nib之前,必须先注册类。

如果collectionView..cellForItemAtIndexPath中的单元格为空,则尝试检查并分配该单元格。

cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"propertyCell" forIndexPath:indexPath];
if (cell == null) {
    Array *xibs = [[NSBundle mainBundle] loadNibWithNamed:@"propertycell" 
...];
cell = xibs[0];
}

我用swift编码,所以可能上面的语法是错误的,但这是我的想法:)

重新加载后,您的单元格会发生什么?你能添加你想要的和发生的事情的屏幕截图吗?同样,在viewDidLoad中注册数据库&在ViewWillDisplay中重新加载数据似乎是错误的,因为在执行ViewWillDisplay时,CollectionView中没有注册数据库。因此,最好重新加载您的collectionView inside viewDidAppearHi,我尝试了您的建议,但仍然存在问题。不幸的是,我不能上传截图来说明这种行为(我是新来的,我没有足够的声誉)。为了精确起见,我在帖子中添加了一些额外的评论。嗨,我已经听从了你的建议,不幸的是我仍然有这个问题。