Gap at top of UITableView with PLAIN cells - uitableview

Does anyone know why a UITableView inside a UIViewController always has a gap above the UITableViewCell. I'm aware that this is expected for Grouped cells, but this is a Plain cell.
How can I remove the gap?

[[self UITableView] setContentInset:UIEdgeInsetsMake(-65, 0, 0, 0)];
That did the trick for me.

One of the proposed answers to the quesion UITableView is getting a gap on top solved this for me, although it's not the approved answer.
Just add this code in ViewDidLoad
self.automaticallyAdjustsScrollViewInsets = NO;
Alternatively, you can set this property on the ViewController in the storyboard.

Related

Adding TableFooterView makes my other views Disappear

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

Fixed row in UITableView

I would like to implement a UITableView / UITableViewController which has a fixed row on top - to search/add contacts. I probably could add an UIView first and an UITableView after to achieve this - I'm not sure if there's a better way to do this. Does anyone know a better solution here ?
what it should look like (e.g. whatsapp)
Yes, you could add an UIView first and an UITableView after for fixing your top row, this is the right solution for this.
You can set a view as headerView of the table view. Have a look at the docs from Apple:
https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instp/UITableView/tableHeaderView
UIView *searchContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
self.tableView.tableHeaderView = searchContainer;
Yes ofcourse,
Take 2 tableviewCell.
make 1 static and fill up with information u want in its Class file,
make another dynamic(basically the reuseable id) and work on it,in the tableviewController.
Position the cells accordingly in the storyboard before u start coding.

Label that displays 'Prototype Cells' in Storyboard displays in simulator

I am using a Table View (not UITableViewController) with dynamic prototype cells.
However, when you drag a single cell into the tableView, a label with the word 'Prototype Cells' is displayed but then, this label (without the word 'Prototype Cells') appears when I run the app in the simulator.
Does anyone know why that is?
Thanks for your help in advance
The "Prototype Cells" label in the storyboard resembles a section header view, so you may be inadvertently generating an empty one. This could happen if you've implemented any of the related UITableViewDelegate methods. For example, the following would do it:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 20;
}
But without seeing a screenshot or your view controller's code, all we can do is guess.
I got the answer here.
self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, -20, 0);
Thank you to everyone for your help.

Can't get UILabel to show properly on top of UITableView

I am struggling to achieve what I thought was nothing but a 1' coding but apparently
adding a UILabel above my UITableView in a UITableViewController is not a piece of cake...?
Here is the code (yes basic, I know):
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 310, 20)];
[[self tableView] addSubview:label];
The result can be seen in the screenshot below, the label on the top right is just half displayed, saying "Balance..."
Please note that if I try to change CGRect origin.y or size.height the UILabel is not displayed at all.
I also tried adding the following, with no change in result:
[[self tableView] bringSubviewToFront:balanceLabel];
I don't care if the UILabel is scrolled up when scrolling up the UITableView, I want it to stick with the first section header.
I know this can be achieved in other ways, using a custom UIView for the header, changing to UIViewController or using a .xib, but really I would like to understand why this happens.
Thanks for any help.
F.
It does look like the header is hiding your label, maybe you could try setting the header background to clearColor. Since you have no control on the table view loop I suspect that after your addSubView somewhere the table builds its own header and does another addSubView.

UITableView + Add content offset at top

I need to add some blank space to the top of my UITableView that does not affect the size of the content area. Shifting the content down or adding a blank cell is NOT what I want to do. Instead I just want an offset.
How?
I'm not sure if I'm following you but I think I'm having the same predicament. In my case I must give some space to the ADBannerView at the top of the screen so what I did was in the viewDidLoad method I added:
[self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)];
the values it takes are UIEdgeInsetsMake(top,left,bottom,right).
Alternatively the same with Swift:
self.tableView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0)
Swift 4.2:
self.tableView.contentInset = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)
Swift 5.1
add the following in viewDidLoad
tableView.contentInset.top = 100
Really that's all there is to it.
override func viewDidLoad() {
super.viewDidLoad()
tableView.contentInset.top = 100
}
You can add an "empty" header view to the table... this would give the initial appearance of the table to have an offset, but once you started scrolling the offset would be gone. NOt sure that's what you want.
If you need a permanent offset and are not already using section headers, then you could create the offset similarly to above by making custom views for the section headers, especially if you just have one section, this could give you the look of a permanent offset.
I can post sample code if it sounds like either of those are what you are looking for.
I combined Jigzat's answer with:
[self.tableView scrollRectToVisible:CGRectMake(0, 0, 320, 1) animated:NO];
in
- (void)viewDidLoad
so the first cell isn't at the top.
Sounds like you want to wrap a 'View' around your UITableView. If you have a UITableViewController in IB the UITableView will automatically be set to the view of UITableViewController. You change view property to a normal UIView and add your UITableView in there and give it a offset.
---Edit---
I just read my post and thought it made little sense :) When you create a UITableViewController you get this (in pseudo code):
UITableViewController.view = UITableView
This means that the actual table will take up the whole space and you cannot even add other views. So you need to change the
UITableViewController.view = UIView
and add your table to that UIView
I combined this answer with this one:
https://stackoverflow.com/a/9450345/1993937
To make the tableView appear at the top of the content inset, so the space at the top isn't cut off by having the tableView scrolled down slightly when the view initially appears. (18 is my top gap)
[self.tableView setContentInset:UIEdgeInsetsMake(18,0,0,0)];
[self.tableView setContentOffset:
CGPointMake(0, -self.songListTable.contentInset.top) animated:YES];

Resources