UITableView section footer not hiding - ios

I have created a UITableView using the Interface Builder I have a section footer space there, I have designed my custom view as the section footer. But I want the section footer to be hidden initially and only load it after a service call.
I have tried
self.tableview.tablefooterview.hidden = YES
self.tableview.sectionFooterHeight = 0.0f
I have also set the height in delegate methods, but the table footer view is not hiding at all. How do I hide the table footer view.

check this Link for how to Hide footer view in UITableView
- (UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}

Use UITableView delegate method :-
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0;
}

Please try to set section footer value to more than 0(zero). I tried to set it as 0.000001 and it works.
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.000001;
}

Please try this code
- (void)viewDidLoad
{
self.tableview.sectionHeaderHeight = 0.0;
self.tableview.sectionFooterHeight = 0.0;
self.tableview.tableHeaderView=[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableview.bounds.size.width, 0.01f)];
self.tableview.tableFooterView=[[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableview.bounds.size.width, 0.01f)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0;
}

Related

iOS: How to add an image on top of all rows in UITableView?

I have to add one background rectangle image on top of all rows in UITableView.
For example, please check the below reference image where a red arrow indicates this image.
This image is appended in tableview itself, because if I scroll the tableView, this image moves alongwith it.
I'd like to know how to insert such an image on top of all rows in UITableView.
I added UITableView in XIB and displaying contents handled in coding.
Please help!
The UITableView has tableHeaderView property
Example:
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 130.0f)];
UIImageView *thumbnail = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 130.0f)];
[thumbnail setImageWithURL:[NSURL URLWithString:[[initDictionary objectForKey:#"cover_image"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
thumbnail.contentMode = UIViewContentModeScaleAspectFill;
thumbnail.clipsToBounds = YES;
[header addSubview:thumbnail];
self.tableView.tableHeaderView = header;
Ref: UITableView Apple Doc
Create a view and set is as a tableHeaderView property of your UITableView.
Example:
// Create a view.
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
0.0f,
320.0f,
70.0f)];
// Customize your view.
// ...
// Set the view as a table view header.
self.tableView.tableHeaderView = headerView;
You can place this code for example in viewDidLoad method of your view controller. Here is what documentation says about it:
tableHeaderView
An accessory view that is displayed above the table.
Based on UITableView Class Reference
You have to mix dynamic with static cells, only the first cell will be static in this case, with the code something like:
#pragma Mark TableView DataSource Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section == 0){
return 1;
}else{
return 10;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.section == 0 ){
//Static cell
static NSString *idCell = #"cell";
UITableViewCell * cell = (UITableViewCell * )[tableView dequeueReusableCellWithIdentifier:idCell forIndexPath:indexPath];
return cell;
}
//Then you code your dynamic cells...
}
Hope it helps!

How can I apply this header/footer margin between UITableViewCells?

This code creates a margin at the top and bottom of the UITableView. How can I modify it to do the same but between each individual UITableViewCell?
// set header height
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
// set header colour
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [UIColor lightGrayColor];
return headerView;
}
// set footer height
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 10;
}
// set footer colour
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [UIColor lightGrayColor];
return headerView;
}
If successful, I'd also like to be able to add similar left and right margins if possible.
Use an extra Background UIView with top, left. bottom and right margin.[red background view in the picture]. Add all other subViews on this view.

IOS - Styling Section Headers in a static UITableViewController - IOS7

Is it possible to style a section header background / font style in a static UITableViewController? I cant see any storyboard option to do this and as the table is static the table methods have been disabled in the.M file - so I'm not sure how to apply styling programatically either?
The UITableViewDelegate protocol defines a method viewForHeaderInSection which can be implemented in your delegate to return custom header views (works for static UITableViews as well). e.g:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// you can get the title you statically defined in the storyboard
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
// create and return a custom view
UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 50.0f)];
customLabel.text = sectionTitle;
return customLabel;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
// return a custom height here if necessary
return 50.0f;
}

Delete the extra separator of UITableView in iOS 7

For my UITableView I have such code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
But when I launch me app, it shows an extra separator. It's not additional cell - it cannot be selected. How can it be fixed?
Eliminate extra separators below UITableView
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [UIView new];
// If you are not using ARC:
// return [[UIView new] autorelease];
}
With iOS7
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}
It is by default in UITableView. You can use templates to create the kind of view you need, in an empty view controller (or) change the frame size of your UITableView in code by creating and allocating your own view.
You can also try to set footer view height to zero, by using next code in UITableViewDelegate class:
- (CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0;
}

How can I remove the vertical spacing between UITableView sections?

I have a grouped table view with a few sections. By default, there is gap between the sections. I've been looking around for a simple way to remove the gap completely without any luck. The best I could do through the Interface Builder is to set the "Section Height" values in the "Table View Size" property section, but these fields do not accept 0 as valid input. Can anyone tell me the best way to sort this out?
The above answer for me did not work, I had to actually create a UIView with a height of 1 and a background color of clear and then set it's y origin coordinate to -1.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -1, tableView.frame.size.width, 1)];
[view setBackgroundColor:[UIColor clearColor]];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
This gave me a Grouped tableView where the section cells would not scroll underneath the headerView and not have padding in-between the sections.
In your table view's delegate, you can implement tableView:heightForHeaderInSection: and tableView:heightForFooterInSection:.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.0;
}

Resources