I've had some issues with my table view and the top cell. I'm using grouped Prototype Cells, and I've come across an issue with the spacing between the top bar and the first cell. As I've seen on other posts, I tried using 'adjust scroll insets' however, this created another problem, with the cell being hidden underneath the navigation bar. When I try changing the translucency of the navigation bar, the spacing returns. I've got some links to the images below.
When you use grouped cell, it's make space automatically in the header section. Try that;
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 5.0;
return 1.0;
}
It's because that you're using Grouped Style. people use this style to add their header for each group.
You should change the style to plain.
In xib, you should change the Style to Plain
Or do this programmaticlly when init the UITableView
UITableView *myTable = [[UITableView alloc] initWithFrame:CGRectZero
style:UITableViewStylePlain];
Related
I would like to implement segmented controls like this (circled with red) :
(When we scroll this view, the segmented controls stay sticky at the top of the view, that makes me think it's a cell on its own ? but I may be wrong).
I have already implemented a custom cell (that displays kind of what is above the red ellipse in the above picture, in purple) and add it to the header of my table view like so :
BigCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"BigCell"];
self.tableView.tableHeaderView = cell;
Now, I think I should create a second cell with the segmented controls in it and add it also to the table header (and not in the section header, because I have many sections with their titles).
Then, I would create a UIView containing this two cells and add this view as the header of my tableView ? Is this a correct way to do it ?
Thank you very much for the help !
I think you have a couple of options.
1) Make a container view to host both of your "cells" (which needn't be UITableViewCells - just views...). Add the singular container view as the table header.
2) Forego using the table header altogether and just place your views above the table, making it shorter. This is more complicated if you're using a UITableViewController, but simple if you're just hosting a UITableView in some other custom UIViewController.
this is an example with uilabel that stick to the top - just change it to your uisegmentedcontrol
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *viewForSectionHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, SETTINGS_HEADER_HEIGHT)];
[viewForSectionHeader setBackgroundColor:[Utils colorHeaderBlue]];
UILabel *lblSectionTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, SETTINGS_HEADER_HEIGHT)];
lblSectionTitle.text = #"PROFILE";
lblSectionTitle.textAlignment = NSTextAlignmentCenter;
lblSectionTitle.textColor = [UIColor whiteColor];
[viewForSectionHeader addSubview:lblSectionTitle];
return viewForSectionHeader;
}
My first problem that i had was that my last UITableViewCell never had a separator which i wanted. I solved it using this code:
self.tableView.tableFooterView = [[UIView alloc] init];
Now that worked perfectly however with one problem. when i add that all my other views disappear. Here is a picture of before i use the one line of code above and after:
How can i fix this?
Set a zero height table footer view, like so:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for.
Have you tried to use the viewForFooterInSection function?
Add a vertical spacing of 0 between your table view bottom and the view's top which is placed below it. And you need to set one view's height fixed either for UITableView or UIView. Add this code of line in viewDidLoad. It will display the separator also for last cell.
self.tableView.tableFooterView = [UIView new];
Screenshot:
May be this help
You have to set translucent property of tab bar controller
see this question to more reference...
iOS 7 TabBar Translucent issue
I make one UITableView Controller had static cell. And I set number of rows 3 in Storyboard. But rows does not set 3, just be made more and more like this screen shot. I don't touch any programatic code. Did I have to make it programmatically?
That's the normal behavior of a UITableView. Even though you only have 3 rows, the view itself extends to the bottom, and it shows where the cells would be if you had data in them. To fix, do one of two things: customize the UITableView so the dividing line between cells is invisible [UIColor clearColor], or change the size of the UITableView's height depending on how many cells you have.
If you add a footerView to the UITableView then it will not extend all the way to the bottom.
I solve this problem on the story board.
Create one more cell. if you want 3cells, then make 4cells.
Make whatever you want on cell. put the UIButton or UILabel any way. But except 4th cell.
Expend your 4th cell's height, to the bottom.
And finally, check hidden in attributes inspector. It makes 4th cell hidden.
That's it!
And I add one image file. I hope it help your work. Thanks.
Simple solution is to set footer's frame to nil:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/*........*/
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
return cell;
}
I would use a regular View Controller and insert a TableView of the required table height.
Then if you really want to you can do stuff with the cell height and label sizes.
I have a UITableView set up on my app, which runs on iOS 7. I has one section and it loads images into custom cells and it scrolls under the navigation bar as well, which is translucent. So initially, the content is below the navbar and it scrolls under the navbar as we scroll down to view more images. For this I have set an initial contentInset of UIEdgeInsetsMake(40, 0, 0, 0). Now sometimes, I need a small header view on my table to indicate types of images on my table. So I have used the following code:
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 30.0;
}
-(UIView*) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
TableSectionHeader *header=[[[NSBundle mainBundle] loadNibNamed:#"TableSectionHeader" owner:self options:nil] objectAtIndex:0];
[header.title setText:[NSString stringWithFormat:#"Type: %#", self.imageType]];
return head;
}
Where TableSectionHeader is custom view I have created for this purpose. Now ideally, the header must float or "stick" either just below the navbar or at the top of the table (which is under the navbar). But in this case, it just rolls off screen. I want the header to stick right under the navbar. Does anyone know how I can achieve this?
Change the table view's style from Grouped to Plain.
From the official documentation, regarding the Plain table view style:
A plain table view can have one or more sections, sections can have
one or more rows, and each section can have its own header or footer
title. (A header or footer may also have a custom view, for instance
one containing an image). When the user scrolls through a section with
many rows, the header of the section floats to the top of the table
view and the footer of the section floats to the bottom.
I am inheriting my view controller from UITableViewController. I have a header (logo), content (uitableview) and now I want to display the footer (uitabbar). But for some reason UITabBar is not visible. The space is being occupied by the UITableView. How can I fix this?
UPDATE 1:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.tableView.tableFooterView = self.tabBar;
}
I'm not sure you can put a UITabBar as a footer of a UITableView.
"footer of the tableView" meaning it won't be visible until you scroll your UITableView all way down past the last cell to then see the footer -- the header and footer of a tableView scrolls with the tableView content itself). Anyway in term of UX this seems very strange.
You probably want instead your UITabBar to always be visible at the bottom of your screen (and not being dependant of the scrolling of your UITableView). To do this, simply use a UITabBarController... that will then contain your UITableViewController (as the viewcontroller associated with one of its UITabBarItem)
[EDIT] See also Apple's View Controller Programming Guide and its paragraph about TabBarControllers.