Skip to content

Commit

Permalink
同步 sectionViewController 和 compactController 当前显示页面
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Sep 2, 2024
1 parent 4004c88 commit 648ff72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion Bark/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
IQKeyboardManager.shared.enable = true
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
let splitViewController = BarkSplitViewController(style: .doubleColumn)
splitViewController.initViewControllers()
self.window?.rootViewController = BarkSnackbarController(rootViewController: splitViewController)
} else {
let tabBarController = BarkTabBarController()
Expand Down
20 changes: 20 additions & 0 deletions Controller/BarkSplitViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class BarkSplitViewController: UISplitViewController {
super.viewDidLoad()
self.preferredDisplayMode = .oneBesideSecondary
self.preferredSplitBehavior = .tile
self.delegate = self
initViewControllers()
}

func initViewControllers() {
Expand All @@ -28,3 +30,21 @@ class BarkSplitViewController: UISplitViewController {
self.setViewController(compactController, for: .compact)
}
}

@available(iOS 14, *)
extension BarkSplitViewController: UISplitViewControllerDelegate {
// 同步 sectionViewController 和 compactController 当前显示页面
func splitViewControllerDidCollapse(_ svc: UISplitViewController) {
guard let index: Int = Settings[.selectedViewControllerIndex] else {
return
}
self.compactController.selectedIndex = index
}

func splitViewControllerDidExpand(_ svc: UISplitViewController) {
guard let index: Int = Settings[.selectedViewControllerIndex] else {
return
}
self.sectionViewController.tableView.selectRow(at: IndexPath(row: index, section: 0), animated: false, scrollPosition: .none)
}
}

0 comments on commit 648ff72

Please sign in to comment.