Increase height of cell in Application setting screen - iphone

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

Related

Height of cells in different tableViews in iOS

In my view, i have three different tables. For first two tables, i have a fix height for each cell(e.g. say 30.0f for each cell of first table and 45.0f for each cell of second table) which i have adjusted in the storyboard according to the data in each table. For the third table, i want to have a different height for each cell. I tried the method
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
But the issue with this technique is that this method is called for each table. As for the first two tables, i have adjusted the height in storyboard, i don't know what to do with them.And if i do:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView == myTable) {
return 150.0;
}
}
As i have nothing to return for the else cases, the whole thing fails.
Any suggestion?
You need to return a height for the other tables.
If you have set there height in the storyboard you can access that height like so:
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == myTable)
return 150.0;
return tableView.rowHeight;
}
tableView.rowHeight will be the height that you set in the storyboard
You should make your view controller delegate of all 3 tableviews and in heightForRowAtIndexPath check which table called the method:
So in viewDidLoad add:
myTable1.delegate = self;
myTable2.delegate = self;
myTable3.delegate = self;
and then:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView == myTable1) {
return 150.0;
}
else if(tableView == myTable2) {
return 75.0;
}
else if(tableView == myTable3) {
return 75.0;
}
}
How about using the tag property? Set the tag for each table to a unique number then return height like this:
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (tableView.tag == 1)
{
return 150;
}
return 250;
}

collapsing a UITableView

Hey everyone I made a UITableView in my app and when a cell is touched it expands the problem I am having is it does not collapse no matter what I have tried, I'm sure its something easy i just cant figure it out the only time it does collapse is when it another cell is tapped.
Here is my code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedCellIndexPath = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
if (selectedCellIndexPath) {
selected = YES;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedCellIndexPath != nil
&& [selectedCellIndexPath compare:indexPath] == NSOrderedSame)
return 150;
return 44;
}
You're never changing selectedCellIndexPath to nil, so the current selected row doesn't get changed until a new one is selected. In didSelectRowAtIndexPath you should change the beginning to the following:
if (selectedCellIndexPath == indexPath)
selectedCellIndexPath = nil;
else
selectedCellIndexPath = indexPath;
In selectedCellIndexPath you are storing pointer of indexPath. It can change when you reload table, means indexPath object of same cell can be different when you select it second time.
It's safer if you store indexPath.section & indexPath.row
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(_section == indexPath.section && _row == indexPath.row)
{
_section = -1;
_row = -1
}
else
{
_section = indexPath.section;
_row = indexPath.row;
}
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
if (selectedCellIndexPath) {//change it as per your requirement
selected = YES;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(_section == indexPath.section && _row == indexPath.row)
return 150;
return 44;
}
I have created the collapsing UITableView
https://github.com/floriankrueger/iOS-Examples--UITableView-Combo-Box/zipball/master
http://www.codeproject.com/Articles/240435/Reusable-collapsable-table-view-for-iOS
https://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
it's working great..
When you call row reload function does it enter the cellForRow delegate function? If it does then you should put some functionality to collapse the rows after checking for selected row.

How to set height of cell in grouped style table?

I have made a table with two types of custom cells using interface builder:
Everything works fine, except lower cell's height is same as cell above it. It has everything i put - UIImageView etc...
So I was thinking if it is not possible to change cell height when table style is grouped?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row == 1) {
return 100;
}
return 44;
}
We can use UITableview Delegate Methods :
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1)
{
return 60;
}
else
{
return 44;
}
}
You have to use this
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 75.0f;
}
it is use full for me.

Expand only "one" cell at a time? Currently I can open multiple up

I followed Simon Lee's tutorial on animating uitableview height change, and it's working amazing! The only problem I seem to be facing is that I can tap several cells, and they all will remain expanded regardless if another is already expanded. I only want one expanded at any given time, and if another is already expanded, for it to be closed before a new one expands.
Simon mentioned that we should "store a single NSIndexPath as the current selected item instead on an array of indexes." I'm not exactly sure how to do this. If anyone could help out that would be awesome!
what you have to do is just add the code below in the tableView delegate method tableView:didSelectRowAtIndexPath: below the line
[selectedIndexes setObject:selectedIndex forKey:indexPath];
code to add
NSArray *key = selectedIndexes.allKeys;
for (int i = 0; i < [key count]; i++) {
if (![[key objectAtIndex:i] isEqual:indexPath]) {
[selectedIndexes setObject:[NSNumber numberWithBool:NO] forKey:[key objectAtIndex:i]];
}
}
Happy Coding :)
Enjoy the Day!!
Yes you can colapse the cells using the delegate methods of UITableView -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath and - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath :-
First declare the variable to get theindexPath
NSIndexPath *selectedCellIndexPath;
then get the cell's indexPath in didSelectRowAtIndexPath :-
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedCellIndexPath=indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
}
Then do the collapsing and extending and set the lower and upper height:-
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedCellIndexPath != nil
&& [selectedCellIndexPath compare:indexPath] == NSOrderedSame)
return yourCellsExtendedHeightInInteger;
return yourCellsCollapsedHeightInInteger;
}
or use
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedCellIndexPath && indexPath.row == selectedCellIndexPath .row)
{
return 100;
}
return 44;
}
You can see this tutorial also:-

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.