Making the attributes of the first cell of tableviewcell change position - ios

I have a custom header in the table view cell and when i initialise it it overlaps the first cell of the tableview cell and if i increase the size of the first cell of the tableviewcell the buttons and label all go out of their positions .This is the code.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {
return 100;
}
else{
return 75;
}
}
Any ideas on how to increase the height of the first cell without messing up the postion of button and labels?

Related

UITableView Dynamic Cell Height when we have 3 or more Data Source with AutoLayout

I've 3-5 dataSource and in ViewDidLoad() I've mentioned the property for dynamic cell height:-
[self.tableView setEstimatedRowHeight:40.0];
[self.tableView setRowHeight:UITableViewAutomaticDimension];
but the tableview don't update accordingly.. first two-three cell shows contents in good way but as soon as I scroll the tableview, cell gets compressed and then cell shows half of the content.
UPDATED
screen of customCell is
tableViewCell
andConstraints Are:tableViewCellConstraint
I have a UIView in cell and label and a uiimageview inside the view
More Update::
I think its coz i'm also using an empty cell to have a space between two cell and in the delegate method for i doing this
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 20.0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row %2 == 0) {
return 15;
}
return UITableViewAutomaticDimension;
}

Can a cell (UITableView) change its height in real time?

I have a cell with a label, sometimes the label text changes and the cell should be expanded a little bit. I'm using auto layout and variable height cells (you know, UITableViewAutomaticDimension and estimatedRowHeight). It seems it is not working unless after modifying the label I call reloadData or reload that specific cell.
Is that normal? Is there any way to do this automatically or without having to use the view controller to reload the cell that now should have another height? Thanks.
I had a similar problem in one of my apps and what I did was
add 2 constraints, let d be the default height of the label
1. height of the label >= d, priority = 750
2. height = d, priority = 1000
and uitableview cell attribute to UITableViewAutomaticDimension
This worked for me.
try this one
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[[arrFeed objectAtIndex:indexPath.section] objectForKey:#"post_keywords"] isEqualToString:#""])
{
int heigthHeading = [self getHeightForText:[[arrFeed objectAtIndex:indexPath.section] objectForKey:#"post_heading"] withFont:[UIFont systemFontOfSize:17.0] andWidth:245.0];
return 25+heigthHeading;
}
else
{
int heigthHeading = [self getHeightForText:[[arrFeed objectAtIndex:indexPath.section] objectForKey:#"post_heading"] withFont:[UIFont systemFontOfSize:17.0] andWidth:245.0];
return 25+heigthHeading;
}
}
Make cell height dynamic (You can also add multiple label on same cell like this way And your cell increased height depends on labels text)
Add Four Constraints to lable (Top, Bottom, Leading, Trailling)
Set Number Of line 0 and line break mode word wrap
Add this two delegate method
-(CGFloat)tableView:(UITableView )tableView estimatedHeightForRowAtIndexPath:(NSIndexPath )indexPath
{
return 44;
}
-(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath
{
return UITableViewAutomaticDimension;
}

How to add Margins on UITableView to inset content

I have a table view and I want to include margins so that the table's content has some breathing room on the left and right, and also between cells.
I managed to do a table view like:
My Storyboard design is like:
What I did was I added a UITableView to the main view and gave a margin of 10. I added constraints as shown in figure. Changed the Seperator style to None.
Then I added two UITableViewCells.
For Holding the data with custom row height 70.0
Row with same background of parentView with custom row height of 10.0
And implemented the methods like below:
// Row count (Twice as needed, for showing the insect)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 15*2;
}
// Returns cell based on indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
// Decides whether content or inset
if (indexPath.row%2)
{
cell = [tableView dequeueReusableCellWithIdentifier:#"ReuseInset"];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:#"ReuseMe"];
cell.textLabel.text = #"MMP";
}
return cell;
}
// Returns custom row height based on indexpath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ if (indexPath.row%2)
{
return 10.0;
}
return 70.0;
}

UITableview cell row height issue in ios8

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(!isPopover)
{
if (indexPath.row == selectedIndex)
{
return 122;
}
else
return 60;
}
else
{
return 50;
}
}
same method i used in IoS7. Working fine over there.Help me on this
IOS8 sets the tableViewCell row height, depending on whats in the subView of ContentView. If you have a label in the subView and you want to restrict the lines in the label text then use the noOfLines property to restrict the lines and hence the height of the tableViewCell, similarly if you have buttons or images in the tableView you could size them appropriately, such that tableViewCell will size its height accordingly.

Change Height of a UITableViewCell

I want to make a UITableViewCell bigger. How can I do this, I have tried adjusting its frame but nothing happens. What can I do?
You need to implement the
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
method in your UITableViewDelegate.
You can do like this..
//Change the Height of the Cell [Default is 44]:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row == 1) {
return 90;
}
}
return 44;
}
I hope this will help you..
There are 2 steps to change height of a table cell without any additional code:
Select your Table View from your Storyboard. In the Size Inspector change Row Height.
Select your Table View Cell and while it's selected in the Size Inspector change the Row Height.
Note that you MUST set BOTH of Table View's Row Height attribute and Table View Cell's Row Height attribute.
If you just set one of them, it won't work.
I found this answer to be the most informative and most up-to-date to change the height of a table view cell.
TL;DR
Take extra care when making your Auto Layout constraints
Enable row height estimation on your table view in the viewDidLayoutSubviews method.
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44.0; // set to whatever your "average" cell height is
You can use this code for changing the height of different tableview
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == tableView1)
{
return 55;
}
else if(tableView == tableView2)
{
return 75;
}
}
This may help you.

Resources