如何以编程方式显示UISplitViewController Master ?

时间:2021-04-19 15:00:57

I try to show the master of the SVC programmatically.

我尝试以编程的方式显示SVC的master。

The app is universal. I have a TVC on the master and another TVC on the details. The cells on the detail-TVC can be deleted by the user. After the user deleted the last cell in the detail-TVC on iPhone (compact) the master should be shown. On iPad (regular) the next existing cell on the master-TVC is selected and shown (works fine!)

这个应用程序是通用的。我有一个TVC关于master,另一个TVC关于细节。用户可以删除细节- tvc上的单元格。在用户删除iPhone (compact)上的详细- tvc中的最后一个单元格后,应该显示主单元格。在iPad(常规)上,选择并显示master-TVC上的下一个现有单元格(工作正常!)

I tried to perform the displayModeButtonItem's action manually but nothing happens:

我尝试手动执行displayModeButtonItem的操作,但是什么都没有发生:

extension UISplitViewController {
    func toggleMasterView() {
        let barButtonItem = self.displayModeButtonItem()
        UIApplication.sharedApplication().sendAction(barButtonItem.action, to: barButtonItem.target, from: nil, forEvent: nil)
    }
}

For testing a added a "Show" button on the navigation-bar of the detail-TVC and performed the function above.

为了测试在细节- tvc的导航栏上添加的“Show”按钮,并执行上述功能。

@IBAction func do_ShowMaster(sender: BaseUIBarButtonItem) {

    self.navigationController!.splitViewController?.toggleMasterView()

}

Storyboard: 如何以编程方式显示UISplitViewController Master ? Thank you in advance.

故事板:提前谢谢。

1 个解决方案

#1


1  

@IBAction func do_ShowMaster(sender: BaseUIBarButtonItem) {

    self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.allVisible 

}

#1


1  

@IBAction func do_ShowMaster(sender: BaseUIBarButtonItem) {

    self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.allVisible 

}