UICollectionView in UICollectionView - ios

I think that sorry does not speak English well .
I want 4-way scroll. It was constructed as follows.
RootCollection View has vertical scroll.
ChildCollection View has horizontal scroll.
It looks working well. but it has problem.
And once on the first page , scroll to the right.
The vertical scroll twice .
Scroll has already gotta go to the right page .
I think UICollectionview has ReusableCell mechanism.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:#"mainCustomCell" forIndexPath:indexPath];
[cell.collectionView reloadData];
[cell.collectionView setContentOffset:CGPointZero animated:NO];
return cell;
}
i recoded simulator
http://pass2phone.com/files/masse_test.mov

Related

How to change button image for all UICollectionView cells?

I am using a UICollectionView to display some data. I am having one button on each cell. Now on the button click of at some specific index(ex: 9) I want to change buttons image for all cells. Can some one suggest how to do that?
I would loop through all the visible cells and change the image. For example:
for (CustomCellClass *cell in collectionView.visibleCells) {
[cell.button setImage:[UIImage imageNamed:#"new image"] forState:UIControlStateNormal];
}
For off-screen cells, I would make sure to set the new image in collectionView:cellForItemAtIndexPath: as the user scrolls to those cells.
We can simply add the logic in cellForItemAtIndexPath like this.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
if (self.buttonClicked) { // boolean check
[cell.newButton setImage:buttonClickedImage];
}else {
[cell.newButton setImage:buttonNotClickedImage];
}
return cell;
}
After clicking the button, you can also just reload all visible cells.
[self.collectionView reloadItemsAtIndexPaths:self.collectionView.indexPathsForVisibleItems];
Feel free to suggest edits to make this answer better :)

In collection view One item should be shown at a time in screen?

In my project i have collection ,in which horizontal pagination is enabled, Every thing working fine but, when i scroll,particular cell item not fit entire cell,It show half image of previous cell item and half current Items, i need One item to fit the entire screen ??? Any suggestion are welcome
Here is the code:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath; {
SingleItemCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"SingleItemCollectionViewCell" forIndexPath:indexPath];
[cell ConfigaureCollectionViewItem:self.totalCellItems[indexPath.row]]; return cell;
}
-(CGSize)collectionView:(UICollectionView )collectionView layout:(UICollectionViewLayout)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize size = CGSizeMake(self.bounds.size.width - 20, self.bounds.size.height - 40);
return size;
}
Perhaps you should be using UIPageViewController in stead of UICollectionView. From your question it seems that you are trying to mimic the behaviour of the former.

iOS first UICollectionViewCell image not loading ONLY after using constraints

Without constraints my UICollectionViewCells load immediately without any problems at all. When I put constraints on in storyboard so the image view is horizontal and vertically centered to the cell, the first image cell does not load. I have to scroll a few times and then back to the beginning for the first image cell to show. Take the constraints off and it goes back to working perfectly fine.
I thought maybe the images weren't getting loaded in time but that doesn't appear to be the case.
What am I missing?
I can put in some code but it is a pretty standard UICollectionView with custom cell inside ViewController.
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *cell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:#"Cell" forIndexPath:indexPath];
NSString *imageName = [NSString stringWithFormat:#"%#", [self.urlArray objectAtIndex:indexPath.row]];
[cell setImageName:imageName];
[cell updateCell];
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return self.collectionView.frame.size;
}
EDIT:
I just removed the navigation bar and the first 2 images were loading behind the nav bar. They are loading in the size of the default prototype CollectionViewCell. Once I scroll away and back to it, it is the expected size.
When you don't put in constraints, IB automatically puts in constraints for you that give you an absolute position and size based on the frame in the storyboard. Chances are good that the constraints you're adding are not doing what you think they are.
Adding [cell layoutIfNeeded]; right before return cell in cellforitematindexpath fixed it

UITableView duplicate cells

I am making UITableView with many cells.
Than in code, i am adding custom view in cells, and after 10 rows my custom UIView duplicates.
See more in the screenshots.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
EFMyTrainingPreviewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"previewCell"];
"SOME CODE"
return cell;
}
-(void)makeCompleteButtonForWorkOut:(NSIndexPath *)indexPath{
EFMyTrainingPreviewTableViewCell *cell = (EFMyTrainingPreviewTableViewCell *)[_tableviewMyTraining cellForRowAtIndexPath:indexPath];
[_tableviewMyTraining scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
"SOME CODE"
[touchViewCompleteApproach addSubview:view];
}
[cell addSubview:touchViewCompleteApproach];
}
cellForRowAtIndexPath will help you because when you scroll table view it refreshes the cells, and uses custom cells with views and buttons you wish.
It's simple and your code will look nice.
But beware of using addSubview in cellForRowAtIndexPath.
The best approach in your case is to add a subview inside the method cellForRowAtIndexPath. Using the indexPath as the source for getting a reusable cell can lead to reusability buttons.
Wish it helps!

IOS Collection View

I'm new to IOS Development,
I'm designing an interface where I want to use the collection view to place the controls as if in a grid,
For this, I'm using a collection as shown in the picture below
However, at runtime, this screen is appearing completely black:
I was expecting to see the interface I designed as in the first image. But why is the interface appearing completely black?
The default color of UIcollectionView will looks like black only if you want make it visible try to change the View color of UicollectionView and you want to make visible your grid Layout means connect your collection view with delegate and datasource and use collection view delegate functions.
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = #"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
return cell;
}
and this is good tutorial for Uicollection view Look at this link

Resources