UICollectionView Cell not loading - ios

I have a UICollectionViewCell in which I am trying to display a label with some text. I have added the label as a subview of the cell's contentView. But the label only loads on the first cell, and when I scroll, some load and some don't. Why are all the cells not loading? I have tried adding cell.contentView.setNeedsDisplay() and cell.contentView.layoutIfNeeded() before the return cell but none of them work.

you may check few things:
Is your auto-layout done correctly? provide a fixed width and height to your label and add a red background color for example if it is ok then go to next point
maybe the data is not ready for display try to put hardcoded text to your cell label if it works
then you may load data before showing your view and in a background thread.

Check you constraints on collection view.
And also make sure you have set these also
UICollectionViewDataSource
UICollectionViewDelegate
UICollectionViewDelegateFlowLayout

Related

How to add a scrollable view within a collectionView cell

I need to add a scrollview within a collectionViewCell. This is confusing me because there are essentially two ways of scrolling. You can either scroll from one collectionView cell to the next or within a collectionView Cell itself, to get more info from inside the cell. I have attached a picture of what my collectionView cell looks like right now. I would like for the scrollview to scroll within the gray view. How should I set this up in my interface builder?
Thanks so much!
I have also attached the current heirarchy for my scrollview *Scrolling functionality is not working at the moment.
You have a custom collection view cell already just add a scrollView and then anything you want to display in the cell. So your hierarchy would be something like this :
Custom-Cell: ContentView > UIScrollView > then anything you want to add in the view.

What should I do to set up the constraint on UICollectionView

I have a tableview which shows the news. And there's a UICollectionview inside each UITableview cell. Also there'll be some images inside collection view cell and the number of cells cannot be fixed because news may contain one image, two images or more.
The
UITableview cell looks like the following structure :
xxxxxxxxxxxxxxxxxx
name
news info
(UICollectionview img1 img2...)
UIButton and UILabel (such as like, dislike, comment..)
xxxxxxxxxxxxxxxxx
and I also set up the constraints. And I have to set up the width attribute for the UICollectionview. The main issue is that no matter how many images I may have for the news, the collection view will be always that wide and will block the click event for the tableview cell. So any ideas for that,
thx!
here is a suggest:
set the initial width constraint to 0, then changing it to actual width when bind data to cell.

UILabel could not display correctly in the UITableViewCell

the original pic
after i scrolled the tableview
the green Label is a custom label,i use autolayout(masnory) in the tableview for the cell,
but there is something wrong with the cell that the greenlabel on the cell could not display correctly . but when i scrolled the cell out of the screen,once it appears again,everything is ok.
i have tried some methods such as call [self setNeedsLayout] in the configure cell methods ,but it does not work
Click storyboard and find your label and click it later look at bottom side click Resolve Auto Layout Issues and choose -> Add missing constraints or Update constraints will add auto layer constraints and will look good.
Thanks

ios tableView clearColor seperator

I have set my tableView's background color, and I want there is space(10px) around each cell show that color.
e.g.(ignore the red line)
What I am doing now is make the cell embed a smaller view, and set the cell's background to be clear. But it is annoying to create such embed view again and again.
So, I am seeking for a better solution, I believe it would be good if i can increase separator's height. But the old answers did not solve my problem.
(How to increase the UITableView separator height?)
EDIT:
However, if I add my own separator in cell. I may not able to set the cell having round corner
Set the tableView's separatorStyle to .None.
Create a custom UITableViewCell subclass.
In the storyboard (or xib if you created one for the custom cell), add a subview that's inset the amount that you want padded on all four sides.
If you want rounded views, do that on the custom cell's subview (e.g. subview.layer.cornerRadius = 10.0, subview.layer.masksToBounds = true).
Set the custom cell's ContentView to have a clear background.
Set the table view's background to that lovely shade of blue.
Set the cell subview's background color to white.
You don't have to use the cell repeatedly in InterfaceBuilder. Just give the cell an ID, and in your implementation of the table view's data source, dequeue a cell instance using that ID and set the values of the labels inside it.
Have you thought of just making the cell height taller and putting your own separator on the bottom of your custom cells? Nice table layout by the way.

position custom cell in a tableview not fully showing a cell

Okay What i want to do is position a custom cell so that the cell looks like only a portion of it is shown in the UITableView. When you swipe it to the left it goes to a new viewcontroller that allows the user to add details for a new cell. My question is how do we position the UITableViewCell to show only a portion of it in the tableView?
What i want to do is position a custom cell so that the row is not shown fully like about 1/4th or 1/2 its actual length only in the table view
here is an app with the functionality i'm trying to implement this is the image url as i can't post images yet
http://a3.mzstatic.com/us/r30/Purple6/v4/01/16/ec/0116ec99-0206-d125-7d27-d5956b918635/screen568x568.jpeg
I want to implement my cells just like how they implemented their expenses in cells, the cell is positioned according to the amount in it ,if the amount is high the cell is placed further to the left else only 1/4th of the cell is shown(empty cell no expense )
Can we achieve this by making an imageview in a customcell and then changing the x-axis of the image view according to the amount entered in the cell? Thanks in advance
For this, I would do it this way :
For each of my model cell I add a state, in the delegate of UItableView i use heightForRowAtIndex to set the size depends of the cell's state.
To not show extra view (when the cell is cliped) use :
[myCellview setClipToBounds:YES];
I think it should do the tricks. Even if it's not the best way to do it!
Solved it i Just had to add a scroll view to the cell's content view and then add a view containing the color to the scroll view. So its coding is similar to the swipe deletion in 'UITablView'
https://github.com/TeehanLax/UITableViewCell-Swipe-for-Options
this repository helped me out, i only had to make a few changes otherwise that was it thanks for all your suggestions :)

Resources