Reputation: 61
My Application has a navigation and UITableView. I set backgroundColor to my tableView. Look at the picture bellow. I don't understand why the first cell is not started from top of UITableView. When I use View Debbuger in Xcode, TableViewWrapperView is not fulled in UITableView.
I already searched many times. I removed check Adjust Scroll View Insets
and set .zero
tableview's contentinsets
. At last I made New Project and make it again but I can't.
How can I resolve this problem!!
Upvotes: 6
Views: 8610
Reputation: 31
I have try the code below, but it did not work.
self.edgesForExtendedLayout = UIRectEdgeNone;
_tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
My solution:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 1.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0.0,
0.0,
self.tableView.frame.size.width,
1.0)];
header.backgroundColor = [UIColor whiteColor];
return header;
}
Upvotes: 0
Reputation: 89
solution post iOS 11
tableView.contentInsetAdjustmentBehavior = .never
Upvotes: 0
Reputation: 71
Found it for iOS 11 and above, use:
self.tableView.contentInsetAdjustmentBehavior = .never
Upvotes: 7
Reputation: 498
This is for the souls like me who tried everything above and might have missed this. I accidentally used tableview style as Grouped instead of Plain.
So set your Tableview style to "Plain" instead of "Grouped" in xib/storyboard or in code as
Objective C
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
Swift 4,0
self.tableView = UITableView(frame: CGRect.zero, style: .plain)
Upvotes: 7
Reputation: 5223
No need to code for this issue. Just follow below simple step
YourStoryboard.storyboard > YourViewController > Attributes inspector > Uncheck - Adjust scroll view insets.
Here I attached screenshot for reference.
If you like go with code I have also solution :)
- (void)viewDidLoad {
self.automaticallyAdjustsScrollViewInsets = false
}
Upvotes: 12
Reputation: 449
Write this two line on viewdidload of your viewcontroller, it will fix your issue
self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;
Upvotes: 0
Reputation: 412
The table view tries to adjust itself to accommodate the navigation bar assuming that navigation bar is translucent and it has to display itself behind it.
To resolve this issue in the storyboard/xib file set the view controller property extends edges under top bar to false as shown below.
Upvotes: 5
Reputation: 61
I answer my own question.
I don't know what is different to top layout guide
and view
.
But I resolve to set top constraint 0 to view
.
Thank you.
Upvotes: 0
Reputation: 4222
Open the storyboard, click on the UITableView
. In your sizeInspector
set the Header
and Footer
in section height field to be 1.
Upvotes: 2
Reputation: 6157
Open your storyboard and click on the table view controller/view controller that contains the table view. Open the attribute inspector and untick Adjust Scroll View Insets
.
Upvotes: 0