我想在iPad上或基于大小变化特征上使用新的iOS 13表格视图样式.insetGrouped
。
遗憾的是,无法在初始化后更改UITableView样式:https://developer.apple.com/documentation/uikit/uitableview/style
在Storyboard中进行更改也不可行,因为没有办法根据尺寸类别进行更改。
我目前正在使用此代码,但没有任何变化:
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)
}
}
init(coder:)
初始化程序。 - Sulthaninit(coder:)
中设置self.tableView = UITableView(frame: self.tableView.frame, style: .insetGrouped)
,但启动时会崩溃。 - alexkaessnerinit(style:)
来设置样式。这些方法不能混合使用。你不能在创建后更改表格样式,这意味着你不能更改从storyboard加载的控制器的表格样式。 - Sulthan