Custom Collection View

149 Views Asked by At

I have implemented the custom collection view using storyboard. and added a cross button and background image.

When collection view reloading that cross button have been hide for admin and shown for other members which is work perfectly first time.

I have set the tag btn.tag = indexpath.row and assign a function for remove user.

After removing the user and remove the object from the Array when reloading the collection view now that condition I have added for admin to hide button is not working and cross button displayed in all the cells of collection view.

Please anyone help.

        if ([user.type isEqualToString:@"admin"])

        {        [removeBtn setHidden:YES];

                [removeBtn setEnabled:NO];

        }else {

     [removeBtn setHidden:NO];

        [removeBtn setEnabled:YES]; }

Firsttime reloading the collection view result

enter image description here

After Remove Member reloading the collection view result enter image description here

Debug Log After Press Remove Button but cross is now displayed in Admin Item Image.

2016-02-03 11:35:03.620 STT[32132:5629002] Col View 2usertype>    admin
2016-02-03 11:35:03.620 STT[32132:5629002] Hide cross from Admin
2016-02-03 11:35:12.944 STT[32132:5629002] Col View 2usertype>   
2016-02-03 11:35:12.944 STT[32132:5629002] Show cross for Mem
2016-02-03 11:35:17.799 STT[32132:5629002] Col View 2usertype>   member
2016-02-03 11:35:17.800 STT[32132:5629002] Show cross for Mem
2

There are 2 best solutions below

0
On BEST ANSWER

My solution after removing this line (remove.tag=indexPath.row) its working.

3
On

Hope this will help you. //Register class

[self.collectionView registerClass:[CustomCell class] forCellWithReuseIdentifier:@"CustomCellIdentifier"];

at cellForItemAtIndexPath:(NSIndexPath *)indexPath

// Setup cell identifier

CustomCell *cell = (CustomCell *)[collectionView dequeueReusableCellWithReuseIdentifier: CustomCellIdentifier forIndexPath:indexPath];
  User *objUser = [self.UserArray objectAtIndex:indexPath.row];
  [cell updateCellData:objUser]; // set tag here and hide/show + button