Missing items in UIcollectionview on iOS7 - ios

I'm created a collection view of sticker like Facebook Message and add auto layout for them in storyboard. Its ok on iOS 8. But when I'm run its on iOS 7 all items in collection view are disappeared. Can someone tell me what's wrong with my code and how to solve this problem?
Here is my code:
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return stampCategorySelected.templetes.count;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
StampsCollectionViewCell *cell = (StampsCollectionViewCell*) [collectionView dequeueReusableCellWithReuseIdentifier:kStampCellIdentifier forIndexPath:indexPath];
NSString *imgPath = [NSString stringWithFormat:#"%#/%#", STAMP_PATH, stampCategorySelected.templetes[indexPath.row]];
cell.stamp.image = [UIImage imageNamed:imgPath];
//Set page control count
int pageCount = floor(collectionView.contentSize.width / collectionView.frame.size.width) + 1;
_pagesControl.numberOfPages = pageCount;
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(PC_Width/4, PC_Width/4);
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
_clipart.kind = #"stamp";
_clipart.clipartid = [stampCategorySelected.templetes[indexPath.row] stringByDeletingPathExtension];
_clipart.clipartPath = stampCategorySelected.templetes[indexPath.row];
_clipart.index = 0;
_clipart.center = [Utilities arrayFromPoint:DEFAULT_CENTER];
UIImage * clipartImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#/%#", STAMP_PATH, stampCategorySelected.templetes[indexPath.row]]];
if (!clipartImage) {
clipartImage = [UIImage imageNamed:[STAMP_PATH stringByAppendingPathComponent:stampCategorySelected.templetes[indexPath.row]]];
}
_clipart.size = #[#(_templateSize.width/5), #((clipartImage.size.height/clipartImage.size.width)*_templateSize.width/5)];
_clipart.maxscale = 1;
_clipart.scale = 1.0f;
_clipart.angle = 0.0f;
FSLog(#"Selected clipart: %#", _clipart);
[_delegate stampViewController:self didSelectStamp:_clipart];
[self dismiss:nil];
}

Related

Display image in collection view by button click

I want to display random image from array in my UICollectionView. I work with xib, and already create custom cell with image view. I want that when I click my button the image displaying in collection view, but don't know how to do this. I have 2 array in tempArr I initialize images, and in arrayForImages I insert image when button press.
Here is my code:
- (IBAction)randomButton:(id)sender {
NSInteger randIndex = arc4random() % [tempArr count];
NSInteger ind = arrayForImages.count;
[arrayForImages insertObject:tempArr[randIndex] atIndex:ind];
NSLog(#"array for index %#", arrayForImages);
}
Here is the Collection
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return arrayForImages.count;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(100, 100);
}
- (CustomCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"MyCell" forIndexPath:indexPath];
cell.imageViewCell.image = [UIImage imageNamed:[arrayForImages objectAtIndex:indexPath.row]];
return cell;
}

UICollectionViewFlowLayoutBreakForInvalidSizes error

I have an UICollection View i am using the peek and pop method to look into it normally it works fine but if i use peek and pop i get the error
The code for the collection view class
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
AppsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
cell.titleLabel.text = #"TwitClient";
cell.iconimg.image = [UIImage imageNamed:#"twitclient"];
cell.appsbutton.userInteractionEnabled = NO;
cell.appsbutton.hidden = NO;
cell.appsbutton.alpha = 0.0;
cell.phoneImageView.image = [UIImage imageNamed:#"app3"];
cell.descLabel.text = #"TwitClient is an app which helps you find tweets on any subject from around the earth. You can search tweets with or without hashtags";
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(69, 126, 277, 490)];
imageView.image = [UIImage imageNamed:#"T-2"];
[cell addSubview:imageView];
return cell;
}
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0, 0, 0, 0);
}
This is where 3d touch is implmented
- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
AppsViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"...."];
previewingContext.sourceRect = self.appsView.frame;
return appsvc;
}
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
[self presentViewController:viewControllerToCommit animated:YES completion:nil];
}
I dont really know what i have done wrong i have done another collection View like this but no error's

How to add Load more cell in UICollectionView?

I want to add load more cell in UICollectionview ? can anyone tell me how can i add load button ? i have created collectionview that works fine but i want to add Load more button in bottom of collection view cell like this
Here's my collection view
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 3;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
switch (section) {
case 0: return 66;
case 1: return 123;
}
return 31;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSUInteger count = [self.stockImages count];
if (row == count) {
//Add load more cell
}
DemoCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[DemoCellView reuseIdentifier] forIndexPath:indexPath];
// Configure the cell
cell.titleLabel.text = [NSString stringWithFormat:#"%ld", (long)indexPath.item + 1];
NSLog(#"%#", self.stockImages[indexPath.item % self.stockImages.count]);
cell.imageView.image = self.stockImages[indexPath.item % self.stockImages.count];
return cell;
}
#pragma mark <DemoLayoutDelegate>
- (void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// Do something
// Insert new cell after clicking load more data
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout: (UICollectionViewLayout *)collectionViewLayout heightForHeaderInSection:(NSInteger)section {
return kFMHeaderFooterHeight;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForFooterInSection:(NSInteger)section {
return kFMHeaderFooterHeight;
}
You can Add a footer
- (UICollectionReusableView *)collectionView:(JSQMessagesCollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
{
if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
//load your footer you have registered earlier for load more
[super dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
withReuseIdentifier:#“load more footer”
forIndexPath:indexPath];
}
return nil;
}
In your cellForItemAtIndexPath method you can check this:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ImageCollectionViewCell *cellImage;
AddMoreCollectionViewCell *addMoreCell;
if(indexPath.row < [_dataSource numberOfItems]){
cellImage = [collectionView dequeueReusableCellWithReuseIdentifier:ImageCollectionCellIdentifier
forIndexPath:indexPath];
[cellImage configureForMediaViewModel:[_dataSource mediaViewModelForItemIndex:indexPath.row] delegate:self];
return cellImage;
}else{
addMoreCell = [collectionView dequeueReusableCellWithReuseIdentifier:AddMoreCollectionCellIdentifier
forIndexPath:indexPath];
addMoreCell.delegate = self;
return addMoreCell;
}
}
where ImageCollectionViewCell is the main kind of cells and AddMoreCollectionViewCell is a cell with a plus ('+') symbol and other stuff.
With this method, AddMoreCollectionViewCell always add at end of your collection view.
Hope it helps!

UICollectionView reloadData doesn't work correctly

I'm face a strange problem, when I execute from an action (button) the reloadData of my UICollectionView the cells are not displayed correctly, only the background image of the cells are ok.
My "INVPropertyCell" is composed with a background image and 2 labels (title & price). When I execute the reloadData the above labels from cells disappeared randomly.
I have done a lot of searches in the different forums, some people have the same problem but I didn't find out a fix.
Below, you will find my code, if someone can help me it would be very very appreciated.
Jérôme.
- (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];
}
i think,you have to register class before register nib for both INVPropertyCell and INVPropertyHeaderSection cell.
You try check and alloc cell if it is null in collectionView..cellForItemAtIndexPath
cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"propertyCell" forIndexPath:indexPath];
if (cell == null) {
Array *xibs = [[NSBundle mainBundle] loadNibWithNamed:#"propertycell"
...];
cell = xibs[0];
}
I'm coding in swift, so maybe above syntax is wrong, but this is idea :)

Collection view working on both iphone but half showing in ipad

In my application,I am using Collection view as i'd take in Xib.now there is image of array come from server side. And they are correctly seen in both iphone 3.5 and 4 inch screen.But when i select device as ipad it seem like this:
There are three rows appear and i don't know how to solve this problem.I want only one row which will be scrollable.
Here is my code:
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [imagArr count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
QBAssetsCollectionViewCell *cell = (QBAssetsCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:#"QBAssetsCollectionViewCell" forIndexPath:indexPath];
NSDictionary *imageName = [[imagArr objectAtIndex:indexPath.row] objectForKey:#"Content"];
NSString *sr = [imageName objectForKey:#"text"];
cell.Img.image = [self decodeBase64ToImage:sr];
//[cell updateCell];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"%ld",(long)indexPath.row);
NSDictionary *imageName = [[imagArr objectAtIndex:indexPath.row] objectForKey:#"Content"];
NSString *sr = [imageName objectForKey:#"text"];
cloud.image= [self decodeBase64ToImage:sr];
[self.collectionView setHidden:YES];
}

Resources