Is it possible to insert IndexPath values into NSSet? basically Im trying to insert indexPath into my NSSet which is a set of all the turnedGreenCells into my CollectionView, but for some reason it doesn't work :\
Here's my Code:
ViewController.m
Edit: I added all the code to make it easier.
#import "ViewController.h"
//#import "CollectionViewTest-Swift.h"
#import "CustomCollectionViewCell.h"
#import "AppDelegate.h"
#interface ViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, ImpressionStalkerDelegate, UIScrollViewDelegate, UICollectionViewDelegateFlowLayout>
#property NSArray *indexPathsOfCellsTurnedGreen_Arr;
#property NSMutableSet *indexPathsOfSeenCells;
#property ImpressionStalker *impressionEventStalker;
#end
#implementation ViewController
{
}
#synthesize Collection_view;
- (void)viewDidLoad {
[super viewDidLoad];
self.impressionEventStalker = [[ImpressionStalker alloc] initWithMinimumPercentageOfCell:0.70 collectionView:Collection_view delegate:self];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.myViewController = self;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// [impressionEventStalker stalkCells];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 100;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"CELL_ID" forIndexPath:indexPath] ;
// cell.textLabel.text = [NSString stringWithFormat:#"%ld", indexPath.row];
[cell configure:[NSString stringWithFormat:#"%ld", indexPath.row] configure: NO];
// cell.cellBackground.backgroundColor = [UIColor redColor];
// if ([_indexPathsOfCellsTurnedGreen_Arr containsObject:indexPath]) {
// cell.cellBackground.backgroundColor = [UIColor greenColor];
// } else {
// cell.cellBackground.backgroundColor = [UIColor redColor];
//
// }
if ([_indexPathsOfSeenCells containsObject:indexPath]) {
cell.cellBackground.backgroundColor = [UIColor greenColor];
} else {
cell.cellBackground.backgroundColor = [UIColor redColor];
}
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake( [ [UIScreen mainScreen]bounds ].size.width - 40, 325);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 20, 0, 20);
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
[(CustomCollectionViewCell*)cell startTimer:^{
[self.impressionEventStalker stalkCells];
}];
}
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
[(CustomCollectionViewCell*)cell stopTimer];
}
- (void)sendEventForCellAtIndexPath:(NSIndexPath * _Nonnull)indexPath {
CustomCollectionViewCell *cell = (CustomCollectionViewCell*)[Collection_view cellForItemAtIndexPath:indexPath];
cell.cellBackground.backgroundColor = [UIColor greenColor];
// [_indexPathsOfCellsTurnedGreen_Arr arrayByAddingObject:indexPath];
// [_indexPathsOfSeenCells setByAddingObject:indexPath];
[_indexPathsOfSeenCells setByAddingObject:indexPath];
NSLog(#"%lu",(unsigned long)_indexPathsOfSeenCells.count);
}
// A func which sends all the seen cells to the server:.
- (NSSet*)sendStalkDataToServer {
return _indexPathsOfSeenCells;
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UICollectionView *Collection_view;
- (NSSet*)sendStalkDataToServer;
#end
NSSet is immutable. setByAddingObject creates a new immutable set, therefore, you would have to assign the result to the property:
self.indexPathsOfSeenCells = [self.indexPathsOfSeenCells setByAddingObject:indexPath];
However, you should ideally use a mutable set, that is, NSMutableSet.
With a mutable set you could simply:
[self.indexPathsOfSeenCells addObject:indexPath];
Also note that your set is never initialized, therefore it is nil the whole time.
You have to put:
self.indexPathsOfSeenCells = [NSMutableSet set];
somewhere.
Related
I'm trying to have a UICollectionViewController inside my UIViewController.
Here's how I set it up
TagsCollectionViewController* tagsCollectionViewController = [[TagsCollectionViewController alloc] initWithCollectionViewLayout:[UICollectionViewLayout new]];
UIView *tagsView = tagsCollectionViewController.view;
[self.view addSubview:tagsView]; // setting up constraings too
And this is my TagsCollectionViewController
#interface TagsCollectionViewController () <UICollectionViewDelegateFlowLayout>
#end
#implementation TagsCollectionViewController
static NSString * const reuseIdentifier = #"Cell";
- (void)viewDidLoad {
[super viewDidLoad];
self.collectionView.backgroundColor = [UIColor yellowColor];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
}
#pragma mark <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 20;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];
return cell;
}
#pragma mark <UICollectionViewDelegateFlowLayout>
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(50, 50);
}
#end
What's strange is that I get yellow view so my collection seems to be working, however I don't get to see any items. But when I present whole controller everything works fine. So the problem occurs only when I'm trying to embed it. What can be the issue?
EDIT: Related: Adding UICollectionViewController to UIViewController Not Working
It looks as if it's a problem with estimating the size of items in the collection. I was able to get results by using the following code after creating a similar example and noticing that cells weren't being requested.
#interface ViewController ()
#property (nonatomic, strong) TagsCollectionViewController *tags;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.itemSize = CGSizeMake(50.0, 50.0);
self.tags = [[TagsCollectionViewController alloc] initWithCollectionViewLayout:layout];
UIView *tagsView = self.tags.view;
[self.view addSubview:tagsView];
}
I'm trying to make a custom keyboard using storyboard. I need to use two collection views. I want the height and width of collection view cell as the height of collection view itself. Constraints are set properly. But cell size is not looking as expected. It is same as what height collection view has on the storyboard.
Here is the code.
#import "MainViewController.h"
#import "UpperCollectionViewCell.h"
#import "LowerCollectionViewCell.h"
#interface MainViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
#property (weak, nonatomic) IBOutlet UICollectionView *upperCollectionView;
#property (weak, nonatomic) IBOutlet UICollectionView *lowerCollectionView;
#property (strong, nonatomic) NSArray *upperData;
#property (strong, nonatomic) NSArray *lowerData;
#end
#implementation MainViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"View Presented");
self.lowerCollectionView.delegate = self;
self.lowerCollectionView.dataSource = self;
self.upperCollectionView.delegate = self;
self.upperCollectionView.dataSource = self;
self.upperData = #[[[DataModel alloc] initWithTitle:#"Bollywood" subtitle:nil color:[UIColor orangeColor]],
[[DataModel alloc] initWithTitle:#"Hollywood" subtitle:nil color:[UIColor greenColor]],
[[DataModel alloc] initWithTitle:#"Tollywood" subtitle:nil color:[UIColor magentaColor]]];
self.lowerData = #[[[DataModel alloc] initWithTitle:#"News" subtitle:#"Very first comment" color:[UIColor blueColor]],
[[DataModel alloc] initWithTitle:#"Tasks" subtitle:#"Second comment" color:[UIColor redColor]],
[[DataModel alloc] initWithTitle:#"Events" subtitle:#"Third comment" color:[UIColor greenColor]]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if(collectionView == self.lowerCollectionView) {
return self.lowerData.count;
}
else if(collectionView == self.upperCollectionView) {
return self.upperData.count;
}
else {
return 0;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
if(collectionView == self.lowerCollectionView) {
LowerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"lower_cv_cell" forIndexPath:indexPath];
[cell setDataModel:self.lowerData[indexPath.row]];
[cell layoutIfNeeded];
return cell;
}
else if(collectionView == self.upperCollectionView) {
UpperCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"upper_cv_cell" forIndexPath:indexPath];
[cell setDataModel:self.upperData[indexPath.row]];
[cell layoutIfNeeded];
return cell;
}
else {
return nil;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if(collectionView == self.lowerCollectionView) {
CGSize size = CGSizeMake(collectionView.bounds.size.height, collectionView.bounds.size.height-10);
NSLog(#"lower height : %#",NSStringFromCGSize(size));
return size;
}
else if(collectionView == self.upperCollectionView) {
CGSize size = CGSizeMake(collectionView.bounds.size.height, collectionView.bounds.size.height-10);
NSLog(#"upper height : %#",NSStringFromCGSize(size));
return size;
}
else {
return CGSizeZero;
}
}
#end
Unable to figure out why cell size is not as expected.
I am trying to create custom cell for UiCollectionView where I need to update each cell from background.
So I have created custom class for each cell named Cell_Obj and updating the cell content from the Cell_Obj itself using a timer.
The below code add an image on cell and increment a counter in each 2 second and display it on new cell label.
On each time when I add new cell using a button on a viewcotroller the cell updating but every cell getting the same value on the label. It suppose to have different counter value as each cell is different instance of Cell_Obj but the counter value and labelTxt(the cell number) has the same value when each time the timer triggered.
ViewController.h
#import <UIKit/UIKit.h>
#import "Cell_Obj.h"
#interface ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate>
#property (weak, nonatomic) IBOutlet UICollectionView *collection;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController (){
NSMutableArray *GridArray;
}
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.collection setDelegate:self];
[self.collection setDataSource:self];
// Do any additional setup after loading the view, typically from a nib.
GridArray = [[NSMutableArray alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return GridArray.count;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (Cell_Obj *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
Cell_Obj *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
// cell.label.text = #"123";
/*cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"AppIcon.png",indexPath.row]];*/
return cell;
}
- (void)addImage
{
Cell_Obj *cell = [[Cell_Obj alloc] init];
// cell.label.text = #"123";
//cell.label.text = [NSString stringWithFormat:#"%d",[dvrGridArray count]-1];
NSString * txt = [NSString stringWithFormat:#"%d",[GridArray count]];
[cell updateTextLabelName: txt];
[GridArray addObject:cell];
[_collection insertItemsAtIndexPaths:#[[NSIndexPath indexPathForItem:[GridArray count]-1 inSection:0]]];
/* NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
[arrayWithIndexPaths addObject:cell];
[self.collection insertItemsAtIndexPaths:arrayWithIndexPaths];*/
}
- (IBAction)addClicked:(id)sender {
[self addImage];
}
- (IBAction)changeImage:(id)sender {
// DVR_Obj *cell = [dvrGridArray objectAtIndex:0];
// [cell changeImage ];
// [_collection reloadData];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
Cell_Obj *cell = [_collection cellForItemAtIndexPath:indexPath];
[cell changeImage ];
}
#pragma mark Collection view layout things
// Layout: Set cell size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(#"SETTING SIZE FOR ITEM AT INDEX %d", indexPath.row);
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGSize mElementSize = CGSizeMake((screenWidth/4)-2, (screenHeight/4)-2);
return mElementSize;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 1.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 1.0;
}
// Layout: Set Edges
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
// return UIEdgeInsetsMake(0,8,0,8); // top, left, bottom, right
return UIEdgeInsetsMake(1,1,1,1); // top, left, bottom, right
}
#end
Cell_Obj.h
#import <UIKit/UIKit.h>
#interface Cell_Obj : UICollectionViewCell
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UILabel *label;
- (void)changeImage;
- (void)updateTextLabelName:(NSString*)str;
#end
Cell_Obj.m
#import "Cell_Obj.h"
static NSString *labelTxt ;// = [[NSString alloc] init];
static int counter;
#implementation Cell_Obj{
}
+ (void)initialize {
if (self == [Cell_Obj class]) {
labelTxt = [[NSString alloc] init];
counter=0;
}
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)awakeFromNib {
_imageView.image = [UIImage imageNamed:#"flower1.png"];
_label.text = labelTxt;
[NSTimer scheduledTimerWithTimeInterval:2.0f
target:self
selector:#selector(updateImage)
userInfo:nil
repeats:YES];
}
- (void)updateImage
{
_imageView.image = [UIImage imageNamed:#"AppIcon.png"];
counter++;
NSString * txt = [NSString stringWithFormat:#"%#-%d",labelTxt,counter];
_label.text = txt;
}
- (void)updateTextLabelName :(NSString*)str
{
labelTxt = str;
}
#end
Your each cell is not new cell. Cell_Obj *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath]; this statement reuses your cell with identifier "Cell". To create new cell each time , don't pass indexPath, pass nil instead.
at current i have the following code as shown below:
GroupsViewController.m
#import "GroupsViewController.h"
#import "GroupsHomeViewController.h"
#import "CustomCell.h"
#interface GroupsViewController ()
{
NSArray *arrayOfImages;
NSArray *arrayOfDescriptions;
NSString * _titleForNextVC;
}
#end
#implementation GroupsViewController
{
NSString *reuseIdentifier;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[self GroupsCollectionView]setDataSource:self];
[[self GroupsCollectionView]setDelegate:self];
reuseIdentifier= #"SmallIcon";
arrayOfImages = [[NSArray alloc]initWithObjects:#"A.png",#"B.png",#"C.png",nil];
arrayOfDescriptions = [[NSArray alloc]initWithObjects:#"A",#"B",#"C",nil];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [arrayOfDescriptions count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[[cell IconImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
[[cell IconLabel]setText:[arrayOfDescriptions objectAtIndex:indexPath.item]];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *) [self collectionView:collectionView cellForItemAtIndexPath:indexPath];
_titleForNextVC = cell.IconLabel.text;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"GroupsHomeSegue"]) {
GroupsHomeViewController *vc = (GroupsHomeViewController *)segue.destinationViewController;
vc.titleText = _titleForNextVC;
}
}
- (void)setTitleText:(NSString *)titleText {
_titleText = _titleForNextVC;
// Set Title of your ViewController
self.title = _titleText;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
// Toggle View Button
- (IBAction)cellToggleAction:(id)sender {
if([reuseIdentifier isEqualToString:#"SmallIcon"]){
reuseIdentifier=#"ListView";
[sender setImage:[UIImage imageNamed:#"LargeIcon"]];
}
else if
([reuseIdentifier isEqualToString:#"ListView"]){
reuseIdentifier=#"LargeIcon";
[sender setImage:[UIImage imageNamed:#"SmallIcon"]];
}
else if
([reuseIdentifier isEqualToString:#"LargeIcon"]){
reuseIdentifier=#"SmallIcon";
[sender setImage:[UIImage imageNamed:#"ListView"]];
}
[self.GroupsCollectionView reloadData];
}
//Toggled Cell Sizes
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize cellSize;
if([reuseIdentifier isEqualToString:#"SmallIcon"])
cellSize = CGSizeMake(100, 130);
else if
([reuseIdentifier isEqualToString:#"ListView"])
cellSize = CGSizeMake(320, 50);
else if
([reuseIdentifier isEqualToString:#"LargeIcon"])
cellSize = CGSizeMake(320, 360);
return cellSize;
}
#end
GroupsHomeViewController.m
#import "GroupsHomeViewController.h"
#interface GroupsHomeViewController ()
#end
#implementation GroupsHomeViewController
-(void)viewDidLoad{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Well the problem seems to be that i cannot get to my new ViewController via my custom segue once i have clicked on one of my UiCollectionViewcells. Basically i click a cell in my UICollectionView and the title disappears but it does nothing else. It should open up GroupsHomeViewController and set the title of the View Controller to be the label that is placed within the cell i have just clicked. I can't even see if my current title will even work either as i can't get myGroupsHomeViewController to display.
I assume i am missing a line of code somewhere along the lines, but i am struggling to find out where or what it can be that due to receiving no error message's at all.
Also i would just like to point out that i am new to this and have only been developing my app in my spare time for the past month or so. So it would be greatly appreciated if you were to help me with this problem and i thank you in advance for any direction as to what i may be missing.
So the problem is you need to save off "what ever" your trying to pass to the next view controller in a property. In your case i think you have in _titleForNextVC
next is you need to name your segue in your storyboard e.g "GroupsHomeSegue" then you can
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *) [self collectionView:collectionView cellForItemAtIndexPath:indexPath];
_titleForNextVC = cell.IconLabel.text;
[self performSegueWithIdentifier:#"GroupsHomeSegue" sender:self];
}
then it would work
I am trying to use RFQuiltLayout in my Collection View and I keep running into an size/margin issue. It seems appears fine using the 4s and 5s simulator but when I test it on the 6 or 6plus, the blocks get pushed over to the left side of the screen and leave a large margin on the right.
Not sure what's going on here.
image of problem
storyboard
Here is the code for the collection view controller
.h
#import "RFQuiltLayout.h"
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate, RFQuiltLayoutDelegate, UICollectionViewDelegateFlowLayout>
#property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
#property (nonatomic, strong) NSArray *greekLetters;
.m
#import "ViewController.h"
#import "CollectionViewCell.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
RFQuiltLayout* layout = (id)[self.collectionView collectionViewLayout];
layout.direction = UICollectionViewScrollDirectionVertical;
layout.blockPixels = CGSizeMake(75, 75);
self.greekLetters = #[#"Alpha", #"Beta", #"Cappa",#"Delta", #"Epsilon", #"Zeta", #"Eta", #"Theta", #"Iota", #"Kappa", #"Lambda", #"Mu", #"Nu", #"Xi", #"omicron", #"pi",#"rho",#"sigma", #"tau", #"upsilon", #"phi", #"chi",#"psi",#"omega"];
// [[self collectionView]setDataSource:self];
// [[self collectionView]setDelegate:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma - mark CollectionView DelegateMethods:
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.greekLetters.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *CellIdentifer = #"cell";
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifer forIndexPath:indexPath];
cell.cellLabel.text = [self.greekLetters objectAtIndex:indexPath.row];
return cell;
}
#pragma mark – RFQuiltLayoutDelegate
-(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout blockSizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row %2) {
return CGSizeMake(2, 3);
}else{
return CGSizeMake(2, 2);
}
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetsForItemAtIndexPath:(NSIndexPath *)indexPath {
return UIEdgeInsetsMake(5, 5, 5, 5);
}
#end
Not sure what could be causing it.
Any help is greatly appreciated.
thanks.
just play with the blockpixels
for mine these values work perfectly
layout.blockPixels = CGSizeMake(106.66, 106.66);