Set UITableView content inset permanently
Probably it was some sort of my mistake because of me messing with autolayouts and storyboard but I found an answer.
You have to take care of this little guy in View Controller's Attribute Inspector
It must be unchecked so the default contentInset
wouldn't be set after any change.
After that it is just adding one-liner to viewDidLoad
:
[self.tableView setContentInset:UIEdgeInsetsMake(108, 0, 0, 0)]; // 108 is only example
iOS 11, Xcode 9 update
Looks like the previous solution is no longer a correct one if it comes to iOS 11 and Xcode 9. automaticallyAdjustsScrollViewInsets
has been deprecated and right now to achieve similar effect you have to go to Size Inspector where you can find this:
Also, you can achieve the same in code:
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}
UITableView ContentInset and ContentOffset
Not sure if it's the best way but I fixed it by adding:
tableView.contentOffset.y = -70
after the line:
tableView.contentInset = UIEdgeInsets(top: 70, left: 0, bottom: 50, right: 0)
UITableView + Add content offset at top
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)
UITableView extra space at bottom
Ok, I got it.
The "Adjust Scroll View Insets" was marked on my viewController (not my tableView).
Here is an answer with a detailed explanation
Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7
I have found the cause of my original bug and created a sample project showcasing it. I believe there is an iOS7 bug.
As of iOS7, if you create a UITableView with the Grouped style, but do not have a delegate set on first layout, then you set a delegate and call reloadData, there will be a 35px space at the top that will never go away.
See this project I made showcasing the bug: https://github.com/esilverberg/TableViewDelayedDelegateBug
Specifically this file: https://github.com/esilverberg/TableViewDelayedDelegateBug/blob/master/TableViewDelayedDelegateBug/ViewController.m
If line 24 is active,
[self performSelector:@selector(updateDelegate) withObject:nil afterDelay:0.0];
there will be an extra 35 px space at the top. If line 27 is active and 24 is commented out,
self.tableView.delegate = self;
no space at the top. It's like the tableView is caching a result somewhere and not redrawing itself after the delegate is set and reloadData is called.
iOS7 last cell in UITableView section forces full width separator
After some experimentation I've found the only real solution is to set the UITableViewStyle
to UITableViewStylePlain
and set empty footers using:
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}
This will not be a satisfactory solution for some, because UITableViewStylePlain
does not provide all of the features of UITableViewStyleGrouped
, but it gives me the section without the full-width separator.
Related Topics
How to Make a Call Which Begin with * in Iphone
Alamofire: Sending JSON as Request Parameter
How to Use Charles Proxy on the Xcode 6 (iOS 8) Simulator
Uicollectionview with a Sticky Header
Disable Scroll on a Uiwebview Allowed
iOS Avplayer Trigger Streaming Is Out of Buffer
How to Add Live Camera Preview to Uiview
How to Update Uibutton Title/Text Programmatically
Cropping Center Square of Uiimage
@State Var Not Updated as Expected in Lazyvgrid
Images for Retina Screen (@2X)
What Is Nsmanagedobjectcontext's Performblock: Used For
Frosted Glass (iOS 7 Blur) Effect
How to Remove All Navigationbar Back Button Title
iOS How to Asynchronously Download and Cache Images and Videos for Use in My App