diff --git a/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuController.swift b/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuController.swift index f59a72e..d4e25ed 100644 --- a/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuController.swift +++ b/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuController.swift @@ -92,25 +92,62 @@ open class RSSelectionMenu: UIViewController, UIPopoverPresentatio // MARK: - Init - convenience public init(dataSource: DataSource, cellConfiguration configuration: @escaping UITableViewCellConfiguration) { - self.init(selectionStyle: .single, dataSource: dataSource, cellConfiguration: configuration) - } - - convenience public init(selectionStyle: SelectionStyle, dataSource: DataSource, cellConfiguration configuration: @escaping UITableViewCellConfiguration) { - self.init(selectionStyle: selectionStyle, dataSource: dataSource, cellType: .basic, cellConfiguration: configuration) - } - - convenience public init(selectionStyle: SelectionStyle, dataSource: DataSource, cellType: CellType, cellConfiguration configuration: @escaping UITableViewCellConfiguration) { + convenience public init( + dataSource: DataSource, + tableViewStyle: UITableView.Style = .plain, + cellConfiguration configuration: @escaping UITableViewCellConfiguration) { + + self.init( + selectionStyle: .single, + dataSource: dataSource, + tableViewStyle: tableViewStyle, + cellConfiguration: configuration + ) + } + + convenience public init( + selectionStyle: SelectionStyle, + dataSource: DataSource, + tableViewStyle: UITableView.Style = .plain, + cellConfiguration configuration: @escaping UITableViewCellConfiguration) { + + self.init( + selectionStyle: selectionStyle, + dataSource: dataSource, + tableViewStyle: tableViewStyle, + cellType: .basic, + cellConfiguration: configuration + ) + } + + convenience public init( + selectionStyle: SelectionStyle, + dataSource: DataSource, + tableViewStyle: UITableView.Style = .plain, + cellType: CellType, + cellConfiguration configuration: @escaping UITableViewCellConfiguration) { + self.init() // data source - let selectionDataSource = RSSelectionMenuDataSource(dataSource: dataSource, forCellType: cellType, cellConfiguration: configuration) + let selectionDataSource = RSSelectionMenuDataSource( + dataSource: dataSource, + forCellType: cellType, + cellConfiguration: configuration + ) // delegate let selectionDelegate = RSSelectionMenuDelegate(selectedItems: []) // initilize tableview - self.tableView = RSSelectionTableView(selectionStyle: selectionStyle, cellType: cellType, dataSource: selectionDataSource, delegate: selectionDelegate, from: self) + self.tableView = RSSelectionTableView( + selectionStyle: selectionStyle, + tableViewStyle: tableViewStyle, + cellType: cellType, + dataSource: selectionDataSource, + delegate: selectionDelegate, + from: self + ) } // MARK: - Life Cycle diff --git a/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuDelegate.swift b/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuDelegate.swift index 31faeab..a84e551 100644 --- a/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuDelegate.swift +++ b/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionMenuDelegate.swift @@ -89,7 +89,8 @@ open class RSSelectionMenuDelegate: NSObject, UITableViewDelegate } public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - return self.isSearchBarAdded(tableView).0 ? defaultHeaderHeight : 1 + let height: CGFloat = [UITableView.Style.plain, .grouped].contains(tableView.style) ? 1.0 : 24.0 + return self.isSearchBarAdded(tableView).0 ? defaultHeaderHeight : height } } diff --git a/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionTableView.swift b/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionTableView.swift index 75edf3a..9cb9928 100644 --- a/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionTableView.swift +++ b/RSSelectionMenu/RSSelectionMenu/Source/RSSelectionTableView.swift @@ -72,8 +72,19 @@ open class RSSelectionTableView: UITableView { // MARK: - Life Cycle - convenience public init(selectionStyle: SelectionStyle, cellType: CellType, dataSource: RSSelectionMenuDataSource, delegate: RSSelectionMenuDelegate, from: RSSelectionMenu) { - self.init() + convenience public init( + selectionStyle: SelectionStyle, + tableViewStyle: UITableView.Style, + cellType: CellType, + dataSource: RSSelectionMenuDataSource, + delegate: RSSelectionMenuDelegate, + from: RSSelectionMenu) { + + if #available(iOS 13.0, *) { + self.init(frame: .zero, style: tableViewStyle) + } else { + self.init() + } self.selectionDataSource = dataSource self.selectionDelegate = delegate diff --git a/RSSelectionMenuExample/RSSelectionMenuExample/SingleSelectionHandler.swift b/RSSelectionMenuExample/RSSelectionMenuExample/SingleSelectionHandler.swift index 03f3ccd..7802a35 100644 --- a/RSSelectionMenuExample/RSSelectionMenuExample/SingleSelectionHandler.swift +++ b/RSSelectionMenuExample/RSSelectionMenuExample/SingleSelectionHandler.swift @@ -23,7 +23,12 @@ extension ViewController { // Cell configuration following parameters. // 1. UITableViewCell 2. Item of type T 3. IndexPath - let selectionMenu = RSSelectionMenu(dataSource: simpleDataArray) { (cell, item, indexPath) in + var tableViewStyle: UITableView.Style = .plain + if #available(iOS 13.0, *) { + tableViewStyle = UITableView.Style.insetGrouped + } + + let selectionMenu = RSSelectionMenu(dataSource: simpleDataArray, tableViewStyle: tableViewStyle) { (cell, item, indexPath) in cell.textLabel?.text = item } @@ -151,7 +156,7 @@ extension ViewController { menu.cellSelectionStyle = self.cellSelectionStyle // show as Popover - menu.show(style: .popover(sourceView: sender, size: nil), from: self) + menu.show(style: .popover(sourceView: sender, size: nil, arrowDirection: .down, hideNavBar: true), from: self) }