The 2 rows on top (Monthly, Annual) are a different section than the 3rd row at the bottom (Lifetime). I want to remove the space that is above the Lifetime row in between the sections. I tried changing the header height to 1.0 in the heightForHeaderInSection method but it didn't seem to work.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
CGFloat headerHeight = 0.0;
switch (section) {
case 0:
headerHeight = [self featuredProductHeaderView].frame.size.height;
break;
case 1: {
if (_groupOneSectionTitle) {
headerHeight = 1.0;
}
}
You need to set the footer height as well, and make sure you are not returning a title for header/footer nor are you returning a view for header/footer.
Related
I have UITableView with two sections. Now, because I wanted additional space for header between 0 and 1st section, I've gave them different heights:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
switch (section) {
case 0:
return 30;
break;
case 1:
return 60;
default:
return 0;
break;
}
}
Now, this is working pretty good, I have space view and then in last 30px of view I have label. Problem is when that view is scrolled on top, there is 30px spacing between navigationBar and label(that space view that I made).
Is there any way to detect is header of section 1 is scrolled to top and change height for it if it's on top?
Try to change your tableview to group style
tableView.style = UITableViewStyle.Grouped
After I reviewed what I could do, I've removed this space view and added height for footer in section 0.
I would like to eliminate the space in these two places programatically?
I have tried this without much luck:
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section {
return 35.50;
}
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
UPDATE:
I have seen this solution and it doesn't help me.
After applying the suggested solution of
self.yourTableView.sectionHeaderHeight = 0
self.yourTableView.sectionFooterHeight = 0
I get this, but thats not correct. The whole section title is gone.
It looks like your cell have margin
Open Debug>Debug view hierarchy and see where is your margin
Why you return 35.5 in the heightForHeaderInSection? It is your header height?
Try this and remove heightForHeaderInSection and heightForHeaderInSection functions from your UITableViewDelegate:
self.yourTableView.sectionHeaderHeight = 0
self.yourTableView.sectionFooterHeight = 0
Or this
-
(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section {
return 0;
}
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section {
return 0;
}
I give you clear reference from below link
Click Here
Credit goes to Tomen
I understand that using a dynamic TableView, you can set the Cell Height using...
tableView:heightForRowAtIndexPath:
However, if I am using A Static Table View ( not Dynamic), With Sections, I would like to programmatically set the height of a cell to 0.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//used to set the height of a cell
CGFloat result;
switch(indexPath.section) {
case 0:
{
//How do I get the ROW number in this section?
result = 44;
break;
}
case 1:
{
//this works if I want to set all of the rowels to this height.
result = 250;
break;
}
}
The question asked another way, If I have the indexPath.section... how can I do something like...
indexPath.Section.row?
You can use indexpath.row directly. No need to write indexPath.Section.row.
In iOS, the NSIndexPath gets extra duties. It is a bit confusing as Apple has two different pieces of documentation.
As noted in the other answers, you get:
Getting the Section Index
section property
Getting the Index of a Row or Item
row property
item property
I am trying to create a grouped table view with 3 groups, and each group has cells that are a different height. I've set up 3 prototype cells in my Storyboard with the appropriate heights, and have set up my UITableViewController to return the appropriate heights for each row. However for some reason all of my cells are only 1 pixel tall when they appear on screen.
I've stepped through the code and the correct height and cell is returned for each row. I've also verified that the frame of each cell is correct before it is returned. However calling rectForRowAtIndexPath reveals that the rect for each row is only 1 pixel tall.
This problem goes away entirely when using a constant cell height. In that situation the cells display perfectly, some of them are just too short/tall since they should be variable height.
Any ideas what is going on here? I'd like to undertand how the rect for each row is determined when using heightForRowAtIndexPath.
Code for heightForRowAtIndexPath:
- (NSInteger)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section) {
case 0:
return 80.0;
break;
case 1:
return 260.0;
break;
case 2:
return 110.0;
break;
case 3:
return 114.0;
break;
default:
break;
}
return 0;
}
You have declared tableView:heightForRowAtIndexPath: to return NSInteger.
That should be CGFloat.
simply to increase the height for row .simply write the method for height for row at indexpath an simply written
if (indexpath.section== 0)
return 50;
I am using variable heights for my UITableViewCells. This works fine normally however
I am finding that whatever the very last cell's height is, that becomes the height for all of the blank cells below it.
Is there a way to set a default height for the blank cells that appear below the last cell?
Thanks.
if you are using switch statement then set the default height for empty cells in default case of switch. Like so
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
int rowHeight = 40;
switch (indexPath.row) {
case 0:
rowHeight = 80;
break;
case 1:
rowHeight = 300;
break;
default:
rowHeight = <your default value>;
break;
}
return rowHeight;
}