UILabel could not display correctly in the UITableViewCell - ios

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

Related

UITableView edit mode appears on top of my views

edit mode problem
As you can see in the picture, when I enter the edit mode the delete button appears on top of all the views in the cell.
I assume this is because I am using programmatic UI with autolayouts not the storyboard and some of the constraints are preventing actions, but I cannot find out how I can resolve this issue.
I suspect that when creating your UITableViewCell subclass, you did not add your custom subviews to the cell's contentView.
From the documentation:
The content view of a UITableViewCell object is the default superview for content that the cell displays. If you want to customize cells by simply adding additional views, you should add them to the content view so they position appropriately as the cell transitions in to and out of editing mode.
Sounds like your problem exactly.

Hiding UI elements in UITableViewCell and resize cell according

What is the best approach to hide UI elements in a UITableView with UITableViewAutomaticDimension?
I have multiple labels, buttons, imageviews in a cell. For specific condition I want to hide some of them and want the tableview to resized accordingly.
Kindly correct me if I'm missing something.
Use StackView.
StackView will manage it, when elements hide they resize automatically.
use StackView in tableview cell
Click Here for how to use StackView
Click Here For Example, This will help you to more understand.
If you are using UITableViewAutomaticDimension then you must update constraints programatically.
i.e if you have 2 labels and 2 button, and if you want to hide on label on click of one of button. then you have to manage height constraints of that label to manage automatically manage cell heigh.

UICollectionView Cell not loading

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

UITableViewCell is loading content only on scroll

I am trying to create a UITableView
Here is the code sample
https://www.dropbox.com/s/1t2wnpo110o2r9n/TableBug.zip?dl=0
The problem is , the UITableViewCell only shows 1 cell and shows other cells only after Scroll
OK, after running your code you have one problem.
Because you have an image as a subView of your cell and the image is larger then the cell, some time it will be drawn outside of the cell and hide other cells
So go the StoryBoard and select the table view cell and in the attribute inspector check the "clip subviews" button.
This should solve your problem (it did for me when i run your code)

how to expand and collapse the UItable view cell on button click

Has anyone seen a script like this or would be willing to help out with one?
Collapse/Expand Button
The uitableview cell to be expanded partially open (giving a preview in essence)
After the button is pressed then the cell of table would expand to show the entire contents (with a nice fade effect). If you chose to collapse the cell then it would return to the original offset (preview) height.
Has anyone seen anything like this? I've found a plethora of these scripts that fully expand or collapse, but not like this
Thank you for any help!!
you have to make custom cell class. While creating cell give the height of the cell as maximum you want (i.e when it expands) and when creating the custom cell drag a UIView and put all the contents in this view and hides this view. Then when button is being Tapped just you have to make it unhidden.

Resources