iOS 8 UITableView separator inset 0 not working
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
iOS 8 introduced many changes and updates to the UIKit framework, one of which was a change in behavior regarding UITableView. Developers noticed that setting UITableView separator insets to zero didn't work as expected, causing a lot of confusion and frustration in the community. This article explores the details of this issue, providing technical explanations and potential workarounds.
Background on UITableView Separator Insets
UITableView is a key component used to display lists in iOS applications. It includes a feature to customize separator insets, which control the space around the cell separators. Prior to iOS 8, developers could set these separator insets to zero, aligning separators with the edges of the screen.
Problem Introduction in iOS 8
With the release of iOS 8, developers noticed that setting the separator insets to zero did not produce the expected results. Instead of aligning the separators to the full width of the screen, there appeared to be default padding that could not be removed by simply setting the insets to zero.
Technical Explanation
The issue arose because iOS 8 introduced a change in the default behavior of insets due to updates in the underlying layout system and its content layout guides. The introduction of automatic layout constraints meant UITableViewCell's actual layout margins might not reflect direct changes to the separator insets.
Code Example
Developers often tried setting the insets as follows:
However, this produced inconsistent outcomes, leading to unexpected spacing around the separators.
Workaround Solutions
While a direct fix wasn't immediately available, developers found a few workarounds to circumvent this issue:
Setting layoutMargins for iOS 8 and Above
One approach was to adjust the layoutMargins of the cell’s content view:
Utilizing tableView:willDisplayCell:forRowAtIndexPath:
Another workaround involved overriding the tableView:willDisplayCell:forRowAtIndexPath: method to reset the separator insets manually:
Disabling preservesSuperviewLayoutMargins
Altering the behavior of superview layout margins by setting preservesSuperviewLayoutMargins to NO was crucial:
Summary Table
Here's a concise summary of key points and solutions:
| Issue | Explanation | Solutions |
| Separator Insets Issue | iOS 8 changed default insets, causing unwanted padding | Use layout margins and display methods |
layoutMargins | Affects the cell's separator inset behavior | Set to UIEdgeInsetsZero |
preservesSuperviewLayoutMargins | Controls inheritance of insets from superview | Set to NO |
Additional Considerations
Compatibility with Different iOS Versions
When implementing such workarounds, it's essential to ensure compatibility across different iOS versions. Use conditional checks to apply settings only when appropriate methods or properties are available.
Explore Further Customization
iOS development evolves continuously, and developers can make use of additional customization tools like custom cell classes or adjusting through Interface Builder.
Ongoing Monitoring
Always keep an eye on new updates and documentations from Apple, as future iOS versions might introduce fixes or alter existing behavior. Research and community forums are invaluable for staying updated on best practices.
In conclusion, while iOS 8 introduced a quirk with UITableView separator insets, understanding the new layout system and employing workarounds allows developers to maintain desired UI design effectively.
Related reading
- iOS 9 “fbauth2” missing from Info.plist
- iOS 9 not opening Instagram app with URL SCHEME
- iOS 9 not opening Instagram app with URL SCHEME
- iOS 9 Xcode 7 - Application appears with black bars on top and bottom
- iOS – Run/Debug/Install builds over Wi-Fi
- iOS app crashes, xcode says ''Lost connection to X''s iPhone'' when debugging
- iOS / Android cross platform development
- iOS Access app-info.plist variables in code
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.