Then,
Here are Cell files. File.h:
#import "CollectionViewCell.h"
#import "CarblueGroupObject.h"
@protocol CarblueHorizontalCollectionCellDelegate <NSObject>
-(void)didSelectCarblueHorizontalCellAtSection:(NSInteger)section IndexPath:(NSIndexPath *) indexpath;
@end
@interface CarblueHorizontalCollectionCell : CollectionViewCell <UICollectionViewDelegate , UICollectionViewDataSource>
@property (nonatomic, weak) IBOutlet UICollectionView *collectionView;
@property (nonatomic, weak) IBOutlet UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, strong) NSMutableArray *locationArray;
@property (nonatomic, assign) NSInteger section;
@property (nonatomic, assign) id <CarblueHorizontalCollectionCellDelegate> delegate;
- (void) setCarblueGroupObjet:(CarblueGroupObject*)objGroup displayGroupName:(BOOL)show;
file .m:
@implementation CarblueHorizontalCollectionCell
- (void)awakeFromNib {
// Initialization code
[super awakeFromNib];
self.arrCarblue = [Helper loadFavoriteCarblueObjects];
NSArray* reversedArray = [[self.arrCarblue reverseObjectEnumerator] allObjects];
self.arrCarblue=reversedArray;
[self.collectionView registerNib:[CarblueCollectionViewCell nib] forCellWithReuseIdentifier:@"CarblueCollectionViewCell"];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"goCarblue"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(openCarblue:) name:@"goCarblue" object:nil];
}
-(void)viewDidLayoutSubviews {
self.flowLayout.itemSize =CGSizeMake(200, 65);
}
- (void) setCarblueGroupObjet:(CarblueGroupObject*)objGroup displayGroupName:(BOOL)show
{
self.objCarblueGroup = objGroup;
self.willShowGroupName = show;
}
#pragma mark - UICollectionViewDataSource & UICollectionViewDelegate
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(200, 65);
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section
{
if(_arrCarblue.count==1){
return 1;
}else if(_arrCarblue.count ==2){
return 2;
}else if(_arrCarblue.count ==3){
return 3;
}else if(_arrCarblue.count ==4){
return 4;
}else if(_arrCarblue.count ==5){
return 5;
}else{
return 5;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CarblueCollectionViewCell";
CarblueCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
CarblueObject *obj;
obj=[_arrCarblue objectAtIndex:indexPath.row];
cell.lblCar.text=[NSString stringWithFormat:@"%@",obj.Car];
self.collectionView.scrollsToTop = NO;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
if ([self.delegate respondsToSelector:@selector(didSelectCarblueHorizontalCellAtSection:IndexPath:)]) {
[self.delegate didSelectCarblueHorizontalCellAtSection:self.section IndexPath:indexPath];
}
}
#pragma mark - Refresh Collection
-(void)openCarblue:(NSNotification *)notification
{
if ([[notification name] isEqualToString:@"goCarblue"])
{
[self refresh_collection];
}
}
-(void)refresh_collection{
self.arrCarblue = [Helper loadFavoriteCarblueObjects];
NSArray* reversedArray = [[self.arrCarblue reverseObjectEnumerator] allObjects];
self.arrCarblue=reversedArray;
//self.collectionView.scrollsToTop=YES;
[UIScrollView beginAnimations:@"scrollAnimation" context:nil];
[UIScrollView setAnimationDuration:1.0f];
[self.collectionView setContentOffset:CGPointMake(0, 0)];
[UIScrollView commitAnimations];
[self.collectionView reloadData];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
The strange thing is that if I step from one view to the other, the refresh does not work. But, if I close the app and I open the App again, the refresh works. Why?