Mr. Meeseeks
Mr. Meeseeks

Reputation: 259

Swift UISplitViewController MasterViewController set width not working

I'm working on an app to have a split view and so far it's working fine, but it's not possible to set the width of the master controller using preferredPrimaryColumnWidthFraction. Another screen in the app already contains a split view and there it's working fine to set the width using the preferredPrimaryColumnWidthFraction (this screen has been built some time back) and when comparing both screens I can't find any difference in the storyboards that would explain this behaviour.

The basic setup in the storyboard is the following: enter image description here

The controller in the top right is the HelpMenuController:

import Foundation

class HelpMenuController: UITableViewController {

   override func viewDidLoad() {
      super.viewDidLoad()
      self.splitViewController?.preferredPrimaryColumnWidthFraction = 0.3
   }
   ...
}

For the other screen, the call to set the preferredPrimaryColumnWidthFraction happens as well in the viewDidLoad method of the corresponding MasterViewController. Everything seems to be identical, yet for one split view it's working, for the other split view it isn't.

I also tested it by using a customized UISplitViewController and set the preferredPrimaryColumnWidthFraction in it's viewDidLoad method, but this approach didn't work.

Running out of ideas what could cause this issue - did anyone also experience this issue or has an idea about it?

Albert Einstein:

The definition of insanity is doing the same thing over and over and expecting different results.

Sometimes I have the impression for software development it's the other way around: Insanity is doing the same thing over and over again and expecting the same results.

Or in other words: Same same but different.

Upvotes: 3

Views: 916

Answers (1)

Mr. Meeseeks
Mr. Meeseeks

Reputation: 259

Okay, so after reading the documentation about UISplitViewController again, I found a solution:

class HelpMenuController : UITableViewController {

   override func viewDidLoad() {
      super.viewDidLoad()
      self.splitViewController?.preferredPrimaryColumnWidthFraction= 0.3
      self.splitViewController?.maximumPrimaryColumnWidth = 0.3 * UIScreen.main.bounds.width
   }
   ...
}

For a yet unknown reason to me, the maximum width had to be increased to the desired value for this screen and for the other screen this had not to be done.

Upvotes: 8

Related Questions