footer text in tableview is not showing - ios

I have a basic grouped table view where i have implemented the two methods for setting header and footer for each section. Now, the header text is showing and working just fine. But the text in the footer view is not showing. I have 3 sections and only want to add text to the first footer section. The code:
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
if ( section == 0 ) {
return #"Lorem ipsum";
}
return nil;
}
Now the weird thing is that it seems that the table is actually making space for the text, it's just not showing. I think there might be some really simple explanation to this, but can't seem to find it:)

I guess you are having heightForFooterInSection method in your viewController. If you are returning any value here, it is the problem. If you are doing, change your code like
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (section == 0) {
return 30.0f;
}
return 0.0f;
}

Related

Make UITableViewHeaderFooterView non sticky

I am having a common footer for all cells and I am setting it with
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
I know that by default footers are sticky to bottom of UITableView, I dont want footers to stick to bottom of table, what is best way to achieve this?
One way I know is to add extra row and show footer there, But I am looking for cleaner approach than this.
Can anyone help me with this?
You can set UITableViewStyle as UITableViewStyleGrouped.
Use this initializer.
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
You can set this on storyboard.
You can create an extra uitableviewcell and append at the last of tableview. In the numberOfRowsInSection: method you can add one 1 like
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [objectArray count]+1 ;
}
in tableView:cellForRowAtIndexPath: method
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexpath.row == [objectArray count]) {
//create footer cell
}
else {
//show normal cell
}
}
If you happen to have static height for footer and not changing the contentInsets, you can try this (assuming footer height is 44):
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -44, 0)

Uneven section header size in static UITableView

I've created a simple static UITableView which is embedded in a UINavigationController. I don't understand why the height of the first section header is greater than that of the height of the section header after the first section. I want the height of the section headers to be the same.
Note: I'd like to do everything in the Storyboard if possible.
I don't think you can do this just in Storyboard. The only way I have been able to get things looking the way I want is to implement something like;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section==0)
{
return 25;
}
else
if (section==1)
{
return 35;
} // etc etc
And then, in Storyboard, adjust the Table View Size, Section Height values.

Why do I get a gap between my UISearchBar and my UITableView Cell Header when I touch the UISearchBar on iOS7?

These two pictures should explain it. The first shows my UITableView normally. The second shows when I touch the UISearchBar and it takes focus. Why is there a gap between the cell header and the search bar? Anyone know how to fix this?
iOS 7 is when this occurs by the way. I already have this code:
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return 0;
}
else
{
return 23;
}
}
I fixed this problem in my code by removing the following 2 lines of code.
self.viewController.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationBar.translucent = NO;
Hope that leads you in the right direction.
In iOS 7 there is small area on the top of UITableView. This is the header of UITableView.
Add following code to your controller ( UITableViewDelegate class ).
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 1;
}

Remove space at the top of first row in table view

In my application i'm using custom cell in table view to display images in all rows. But in my .xib file there is a big empty space comes at the top of the custom cell. Can anyone tell me that how remove that space in iOS7 (iPad)? (like how to change the Y axis of the custom cell)
This is an IOS7 related issue with UITableViewStyleGrouped and size of footer views in section.
If you set the footerView to be size 0 it defaults to a larger value, The solution I found was to set the footer to a very small non zero number
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.0000001f;
}
Try to set into your property inspector like this..
This might help you:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectNull];
sectionHeader.hidden = YES;
return sectionHeader;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0;
}
Sometimes the empty space in the first row is the section header space. This functions eliminate it.

UITableView Static Cells - How to limit rows displayed?

On iOS 5
I Have a UITableViewController set to Static Cells. I only need 3 rows which will be filled with content for each row. So I put 3 UITableViewCell. All works fine but when I run the app, it always shows more than 3 rows. The rest of the rows is empty rows. How can I only display the 3 rows I intended to display.
Should I use Grouped style and custom the look?
set footerView to an empty view.
self.tableView.tableFooterView = [UIView new].
this works on dynamic cells. should work on static cells too.
implement these two methods in your UITableViewController:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (section == tableView.numberOfSections - 1) {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
}
return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == tableView.numberOfSections - 1) {
return 1;
}
return 0;
}
In fact, these codes are telling tableview that you don't need to render the seperator line for me anymore, so that it looks the empty cells won't be displayed(in fact , the empty cell can not be selected too)

Resources