UITableview cell row height issue in ios8 - ios

- (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.

Related

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;
}

Making the attributes of the first cell of tableviewcell change position

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?

I'm having trouble resizing a table view cell

I am trying to create a sample app to resize a cell. The cell is staying at the default height of 44px. I am unable to make this change through the storyboard because I have a view with varying height inside the cell. Can this be done with only 1 cell? I have an outlet from the table cell to the variable called cell. My code in the .m file is as follows. Also, all the cells are already static.
self.whereCell.frame = CGRectMake(0, 191, 320, 78);
Have you tried the tableView:heightForRowAtIndexPath: method?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return 191;
}
return 44;
}
This shouldn't been needed if the cell is static though; you should be able to set the height of the cell in Interface Builder.

single cell height in UITableView Xcode 5

Sorry i know this question has been asked before but i can't seem to get it to work, i would like to change the height of the first cell in my UITableView and keep the rest as default 44. I have implemented the below code (tried various others) and my application builds but the cell height does not change. Any help on this would be great.
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return 150;
}
else {
return 44;
}
}
How did this code work out for you?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 0)
return 150;
else
return 44;
}
estimatedHeightForRowAtIndexPath
is used to calculate the position / size of the scroll bar on the side when using autoLayout, not the cell height. You need:
heightForRowAtIndexPath

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