Iphone Table Cell Sizes - iphone

I'm using custom cells in my table view. I have the height of the cells set but for only the 10th cell in the table I need to resize.

You need to implement the UITableViewDelegate method heightForRowAtIndexPath:
Something like this:
- (CGFloat) tableView: (UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ( indexPath.row == 10 )
return 100.0;
return 40.0;
}

Related

Increase height of cell in Application setting screen

I am using this Tutorial for developing application setting screen.The problem is i want to increase height of cell in setting screen.And I have not taken any table view i am doing that by using Root.plist file.i.e i want to increase height of Legal field in this Image (application setting screen not in table view of application)
First, you'll need to save the selected indexPath row:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedRowIndex = [indexPath retain];
[tableView beginUpdates];
[tableView endUpdates];
}
Then, when you have the currently selected index, you can tell the tableView that it should give that row more space.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//check if the index actually exists
if(selectedRowIndex && indexPath.row == selectedRowIndex.row)
{
return 100;
}
return 44;
}
This will return height 100 for the selected cell. You can also check this
Use this set row height in a UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// Return the height For Row.
return 100.0;
}
As it can be seen from your image the indexPath for which you need to increase the row height is section 1 and row 0:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *indexValue = [NSIndexPath indexPathForRow:0 inSection:1];
if (indexValue == indexPath)
return 100.0;
else
return 44.0;
}

Change heightOfPrevious UITableViewCell

Is there anyway I can change the height of previous UITableViewCell when setting height for current cell in - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath?
Have two rows in a UITableView. When in first row, it will set the default height.. When in row two I want to change the height of first row. Is this possible? If so how?
Thanks,
Bharathi.
Try to work with a boolean check if the requirement is fulfilled.
You could do it like this:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0 && !secondRowIsSynced) {
return otherHeight ;
}
else {
return defaultHeight;
}
}
I think you misunderstand tableView:heightForRowAtIndexPath: is called multiple times (once for each row in your table).
If your rows have different heights then you need to determine which row you are on and what height it should have.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
CGFloat height;
if (0 == indexPath.row) {
// This is the first row
height = // what ever you want
} else if (1 == indexPath.row) {
// This is the second row
height = // what ever you want
}
return height;
}
If you later decide that a row needs to be a different height then it is still this method that needs to calculate the correct height to be used for each row. You can force this to be called without reloading the tableView like this
[tableView beginUpdates];
[tableView endUpdates];
bharathi:
You have to reload your table in the didSelectRowAtIndexPath method of UITableView.
You should check that the second row is selected, then reload all the table rows, so all tableview delegate and datasource methods get called again.

Increase the size of tableView Cell..?

Is it possible to increase the size of particular cell in the TableView.
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
{
return 100;
}
By using this we can increase the size of the table cell for a tableView but it will increase all the tableCell size.
But I want to increase the height of first cell is up-to 130 and other cell are of height 100. Can any one suggest me the best way for doing this...
Make height value dependent on cell's position (indexPath), e.g. to make 1st cell higher then others do the following:
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath{
if (indexPath.row == 0)
return 130.0f;
return 100.0f;
}
*Note that with that code if you have several section then 1st cells in all sections will be higher then others.

tableView cell height... how to customize it?

Is it possible to modify height of only one cell in a grouped table view?
I have a table view with 2 sections of 3 and 2 rows... I would change row height of the second row of the second section...
How can I do this?
Thanks!
You can look at this method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
In your case, the code should look like:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1 && indexPath.row == 1) {
return SPECIAL_HEIGHT;
}
return NORMAL_HEIGHT;
}
You can look for more details about the method here
In iOS 8 and above we can use the Dynamic Table View Cell Height.
Using this feature UITableviewCell get its height from its content and We don't need to write heightForRowAtIndexPath
All I have to do in viewDidLoad()
tableView.estimatedRowHeight = 44.0;
tableView.rowHeight = UITableViewAutomaticDimension;
If cell contains uilabel. then apply constraints to uilabel
Make sure you change Label --Lines-- to 0
The cell will grow automatically with content of uilabel:
You can implement the following method to return the height for the row at a given index path:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html%23//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath:
Have a look at
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
For the indexpath just check for which row and section and adjust the height accordingly

How can I increase the height of UITableViewCell dynamiclly

I have an UITableView which includes a list of UITableViewCells. And I set the heights of UITableViewCells in method (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath.
However, I need to increase the height of UITableViewCell when it is selected. For example, the height of UITableViewCell needs to increase 100 pixels when the cell is selected, does anyone know how to do it?
Store selected index in your controller.
Return cell's height depending on that index:
CGFloat height = 30.0f;
...
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return indexPath.row == selectedIndex ? height+100 : height;
}
Refresh tableview geometry in didSelectRowAtIndexPath method (empty block between beginUpdates and endUpdates does the trick):
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
index = indexPath.row;
[tableView beginUpdates];
[tableView endUpdates];
}
Make your delegate method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
return the (new) correct height and make the table view reload the given path.