Too much space between cells - ios

I'm having trouble with reducing the spacing between my cells, I want it to be 1 px. Inside my cell I have a stackView which fills my entire cell, both set to 70.
I can accomplish almost what I want by adding negative constrains, but then my cells gets too big, I only want it to be 70. I set the cell to 70 in the custom cell class
self.frame.size.height = 70
And my stackView is set to the very same. I don't see why I get that amount of spacing between my cells?

Please use the below method to adjust the cell height;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 78;
}

1) Between 2 cells of table view always has no space
2) You set self.frame.size.height = 70 in your custom cell. But it will be useless ! Try this datasource method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
3) Please check the height of the white view

Related

How to increase UITableView Height Dynamically When number of cell is increased using Objective C?

I am new to iOS. I have implemented a table view which is populated with array values successfully, but I'm not satisfied with the result. When I scroll my table view the top values are hiding.
Here is my problem: based on the cell height the table view height should also get increased dynamically in UITableview. How can I accomplish that?
For UITableViewCell dynamic height you can use following delegate by return UITableViewAutomaticDimension
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 300; //give maximum heigh you want
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;
}
and to increase tableview height based on content size use the below line of code
YOUR_TABLE_VIEW_HEIGHT_CONSTRAINT.constant = [YOUR_TABLE_VIEW contentSize].height;
Hope this will help you

Dynamic cell height issue in UitableView using AutoLayout?

I have to calculate dynamic height of cell depends on two label, left label and right label. left label can have empty string . I want to give a specific fixed height if left label is empty else it will take left label height. Cant able to give fixed height when label is empty
This code is not working
self.tableView.estimatedRowHeight = 50
Your constraint for your both label should be,
top,bottom,leading and trailing.
and set below code in your viewDidload
self.tableView.estimatedRowHeight = 50
self.tableView.rowHeight = UITableViewAutomaticDimension;
Set constraints from top and bottom of the cell to both labels.
Then add the following code in your view controller
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}

UITableView Rows Height After Loading Cells

I have UITableView that contains 4 different types of customized cells in storyboard. Each cell has customized UILabels which get variable amount of text data from backend. I am struggling with making the cells resizing correctly. I would really want to change the height of each cell but I can not use heightForRowAtIndexPath because it is called before cellForRowAtIndexPath, but the height is actually calculated within each customized cell.
I tried writing in each cells' height into an array while the UITableView is loading, then just reloading it all over again once, but no effect. I tried using CGFloat rowHeight = UITableViewAutomaticDimension with no success either. The customized labels in each cell definitely grow with text which I see when I just statically change row height to higher numbers. So, I would need somehow my labels to push on rows to make them grow, not sure.
Different similar posts on stackoverflow that I found did not help.
The issue was that I needed to set up top and bottom constraints to the ContentView and NOT to the cell itself in the storyboard.
Label -> ContentView top and bottom constraints need to be set up. And then UITableViewAutomaticDimension specified in viewDidLoad:
self.tableView.rowHeight = UITableViewAutomaticDimension;
estimatedRowHeight should be set too. For example:
self.tableView.estimatedRowHeight = 76.0f;
First Method called is:
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
Second:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Then:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
set a break point in the above methods and test it. So if you want to preset the height use estimatedHeightForRowAtIndexPathmethod.

How to get iOS tableview last right content size with use auto layout

I have a tableview UITableViewAutomaticDimension for auto layout, and I get the tableview content size to make the tableview height as it content height after tableview cell configure and reload, this height isn't right it seems calculate by estimatedRowHeight. I know I can get the last right height use kvo to observe the tableview content size, but I don't know which is the last right one, because I just want do something once when content size is right. How can I do that?
you need to add a delegate method like
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
before that you should pin 4 sides on that contents which you dropped in prototype cell.
now you got the exact row heights of each cells.

How to increase the height of custom cell in UITableView

I have a tableview that fill with custom cells,, Now I want to increase the width of the cell,I increased the cell height of UITableview. But the problem is still same. Any one know how to increase the height of custom cell in UITableView.
Thanks,
If your cell heights vary, implement the following delegate:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44.0; // edit this return value to your liking
}
If they don't, merely set the rowHeight property of your table view instance to whatever height you want all of your cells to be. This answer does a good job of explaining why.

Resources