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.
Related
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.
I'm trying to give space between cells in my tableview for that i written the following code:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
switch (section)
{
case 0:
return 0.0f;
break;
default:
return 15.0f;
break;
}
return 15.0f;
}
up to now everything is fine, but after scrolling tableview gap is not moving when it reaches to top to table. My screens are:
You should not use header view for this purpose. Just design you cells so that their subviews (labels, buttons, images...) are contained in a view that is smaller than the cell itself and centered horizontally. Make the cell background grey, and the subviews' view container white.
The header stops at the top because you have the table style set as plain. If you change the table style to group it will scroll off the top as you are hoping.
So go to the attribute inspector for the tableView and change to style group.
I'm migrating my app to iOS 7, what I have notice is that the space between Table View header and cell is small.
I think this normal behaviour f iOS 7? right.
I was look better before, Is there away to increase space in static UITableView designed using storyboared.
I think this normal behaviour f iOS 7? right.
Yes it is normal behaviour.
Is there away to increase space in static UITableView designed using
storyboard?
In StoryBoard Select tableview then changing the value under the Attributes Inspector .
For all of them which are not finding #Virus answer useful and if you have dynamic headers height for section follow this method
//This method returns the height of a header at a specific section
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
//For example you define heights for these sections
switch (section)
{
case 0:
return 12.0f;
break;
case 1:
return 23.0f;
break;
case 2:
return 56.0f;
break;
case 3:
return 33.0f;
break;
default:
return 25.0f;
break;
}
}
Hope it helps
Playing around with prototype cells and I need to add footer view at the bottom of table view, so a user could see this footer view when he would scroll to the bottom of the table view. So, created demo project with one screen, table view and two prototype cells. Looking for a way how to drag and drop some view below the table using Interface Builder. The problem is it looks like view is put outside table view content, so I see the footer but I can't scroll to it (only a small part of footer view is seen at the bottom of the table view).
I know this should work because already saw a working implementation but cannot figure out what magic setting or code line I need to add.
Here are the methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat rowHeight = 10;
switch (indexPath.row) {
case 0: {
rowHeight = 376;
break;
}
case 1: {
rowHeight = 105;
break;
}
}
return rowHeight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 0: {
Cell1 *cell1 = [tableView dequeueReusableCellWithIdentifier:#"Cell1" forIndexPath:indexPath];
return cell1;
break;
}
case 1: {
Cell2 *cell2 = [tableView dequeueReusableCellWithIdentifier:#"Cell2" forIndexPath:indexPath];
return cell2;
break;
}
}
return nil;
}
Just making 2 row table with two different height cells. Cell1 and Cell2 classes are empty subclasses of UITableViewCell.
Here's how table view and cells look in interface builder:
Here's initial view after launch:
Here's what I see if I scroll to the bottom:
The footer is there, but outside table view (scroll content). As you can see, table view by default reserves some 44px space at the bottom for footer. But if I set footer height in tableView:heightForFooterInSection: then blank spaces appear.
Also, tried to drag and move this view up to view hierarchy in IB, so the view would become a header view. In that case, the view is shown at the top as header view, but then the second cell is shown only partially when scrolling to the bottom. It looks like table calculates how much space it needs to show prototype dynamic cells (have set "Dynamic Prototypes" for the table view). And if you add extra footer or header view to the interface builder then there's less space for the cells (if view is added as header) or the footer is not shown.
UPDATE. If I add this method then blank spaces appear:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 50;
}
Here's what I get in that case (blank spaces below cell2):
UPDATE2 Footer is shown correctly if I disable autolayout.
I think you have missed the following line
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return HEIGHT_OF_YOUR_FOOTER_VIEW;
}
Edit
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *footer=[[UIView alloc] initWithFrame:CGRectMake(0,0,320.0,50.0)];
footer.layer.backgroundColor = [UIColor orangeColor].CGColor;
return footer;
}
Updated
Check this documentation
At last found the solution. Have noticed footer is shown correctly when autolayout is disabled, so started to look at constraints. So, have added leading space to container, trailing space, bottom space and top space to container constraints to table view using Ctrl + Drag. However IB showed red warning about missing Y position constraint. So, after choosing "Add missing constraints" from IB suggestion panel, IB added another system constraint but the footer was still not show correctly. It appears IB was unable to add correct top space and bottom space to container system constraints, and even to fix that. So I'v got 5 system constraints as a result of that:
Adding system constraints using Ctrl + Drag from table view to containing view have worked in previous demos for me. However, this time IB was unable to add correct top space and bottom space to container, and so top space vertical constraint had a value of -568. Tried setting to 0 but it didn't worked. Tried ten times to delete all constraints and add them again. The same result.
So, I deleted all these vertical (bottom and space) constraints and then selected "Add missing constraints". And bingo! IB added correct vertical constraints and the footer view was shown correctly. Here's how correct constraints should look like. However, I still don't understand why IB was unable to add correct constraints when I was doing Ctrl + Drag from table view to container view.
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;