iOS Remove extra space below UITableView - ios

I found this question answered earlier on stack overflow and on other sites too. I tried all options, but yet their is white space below the table. I have 4 prototype cells in my tableview. On storyboard, their is no white space after the 4th cell. But on execution I find white space after the 4th row. Their is no more separator after 4th row, but blank white are is still their.
I tried adding the following code :
- (void)viewDidLoad {
[super viewDidLoad];
_menuItems = [[NSMutableArray alloc] initWithObjects:#"chats", #"visitors", #"agents", #"profile", nil]; //#[#"chats", #"visitors", #"agents", #"profile", nil];
self.tableView.tableFooterView = [UIView new]; //[[UIView alloc] initWithFrame:CGRectZero];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.menuItems count];
}
-(CGFloat)tableView:(UITableView *) tableView heightForFooterInSection:(NSInteger)section {
return 0.01f;
}
-(UIView *)tableView: (UITableView *) tableView viewForFooterInSection:(NSInteger)section {
return [UIView new];
}
To make the whole view look proper, I have set same background color for view and tableview. Everything looks proper except this white area,
Can anyone help me know why do I still l see white area after the last row ? Any help is highly appreciated. Thanks.

MY RowHeight of TableView (44) and TableViewCell (51) was different. I changed the RowHeight of TableView to 51.
And made the Height of TableView which was 220 to 204 (51*4).
Making the RowHeight same and setting tableView Height exactly as RowHeight * number of Rows works for such kind of problem as solution.
Hope this helps someone.

Related

Set background color of UITableView section header to white and make it opaque

I've tried every solution proposed by the community for the background color problem of tableview section headers so I'm now reaching out for help.
I have custom section headers that float (plain style of the table view) and I'd like each header to be displayed on top of the rows. When I scroll the table view, the header background is transparent, and it shows the content of the scrolling row. In order for this to stop, I've tried the following:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
TableHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:#"TableHeader"];
header.event = [events objectAtIndex:section];
[header.contentView setBackgroundColor:[UIColor whiteColor]];
[header.contentView setOpaque:YES];
[header drawHeader];
return header;
}
Nothing changes, and the header is still transparent. Has anyone faced that problem?

Table View "Delete"(on Swipe) coming below indexing [duplicate]

After quite a lot searching around Google, Stackoverflow and apples documentation, I have almost given up.
I am making an app to index costumers and because of a potentially very long list, I use section index to navigate faster. My problem is shown in the picture below.
When I drag an item to reveal the delete button, it is partially hidden below my section index bar.
I have no code setting tableview or tableviewcells width and the section index can't really be changed, as far as i am concerned.
EDIT:
The question is how I can have the tableview cells end before they get overlapped, so the delete button is fully visible.
EDIT 2:
I already tried setting the cell frame smaller without any luck.
cell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, cell.frame.size.width-30, cell.frame.size.height);
I also tried the same with the tableview, but as it is in a UITableViewController it cannot be resized.
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y, self.tableView.frame.size.width-30, self.tableView.frame.size.height);
As a simple work-around we resolved the visual overlap of the index by setting the background color of the index to clearColor.
self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
* This looks visually better, but the index will still overlap your tableViewCell.
Another possible work-around would be to hide the index bar when entering edit mode:
// allow editing
[self.tableView setEditing:YES animated:YES];
// hides the index
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;
The inEditMode method should do the trick. Below I embed a complete code that hides the index while editing and shows it again when the editing is done.
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self inEditMode:YES];
}
-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self inEditMode:NO];
}
//on self.editButtonItem click
-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
[self inEditMode:editing];
}
-(void)inEditMode:(BOOL)inEditMode{
if (inEditMode) { //hide index while in edit mode
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMax;
}else{
self.tableView.sectionIndexMinimumDisplayRowCount = NSIntegerMin;
}
[self.tableView reloadSectionIndexTitles];
}
Just Use this code before allocating any subview in cellForRowAtIndexPath
for (id object in cell.contentView.subviews)
{
[object removeFromSuperview];
}

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.

Problems with UISearchBar not working like in stock apps (scrolling under UINavigationBar)

I've got a problem in that I cannot get my UISearchBar to scroll underneath my UINavigationBar.
-(void)awakeFromNib
{
[super awakeFromNib];
self.tableView.tableHeaderView = self.taskSearchBar;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return self.taskSearchBar;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableView.frame = self.view.bounds;
// Load our table with current data
[self.tableView reloadData];
// Tuck UISearchBar under navigation bar
self.tableView.contentOffset = CGPointMake(0, self.taskSearchBar.frame.size.height);
}
I've spent a LOT of time searching through SO to try to find relevant discussions.
This one, for example, makes it sound OH SO SIMPLE: Scroll UITableView so that the header isn't visible
I was previously able to get this to work when creating everything from Story Board, but I can no longer do that due to the nature of my app - I had to break things out to have a parent UIView to the UITableView which I was unable to do while using a UITableViewController.
Any help on this would be MUCH appreciated!!!
You are assigning the search bar as the tableHeaderView which will be what you need I think. BUT you are returning it as a section header for every section which is not logical(I guess you need this search bar show only in one place). Section headers are always visible and that is what's causing your problem I think.

Resources