I wanted to use the new iOS 13 table view style .insetGrouped
only on iPad or based on size variation traits.
Sadly it's not possible to change the UITableView style after the init: https://developer.apple.com/documentation/uikit/uitableview/style
Changing it in the storyboard is also no option as there is no way to change it based on size classes.
I'm currently using this code, but nothing changed:
class DetailViewController: UITableViewController {
[…]
override init(style: UITableView.Style) {
if UIDevice.current.userInterfaceIdiom == .pad {
super.init(style: .insetGrouped)
} else {
super.init(style: style)
}
}
// Xcode forced me to include this as well?
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
Create UIViewController with `
var tableView: UITableView!
init(...) {
if ??? {
self. tableView = UITableView(style:...)
} else {
self. tableView = UITableView(style:anotherStyle)
}
self.tableView.dataSource = self
self.tableView.delegate = self
}
`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With