Width of Modal Sheet on iPad

3.6k views Asked by At

I am presenting an instance of UINavigationController modally with the modalPresentationStyle set to UIModalPresentationFormSheet. Inside the UINavigationController is an UITableViewController. For a delete button in the table view, I have to know the width of the sheet. Is there any way to access this?

I tried [self.view bounds], however this returns the with of the screen. I think that's because the view is not visible at the time a call this, however I don't know where else I should call it.

2

There are 2 answers

1
AudioBubble On BEST ANSWER
  1. You can directly measure and store a magic value for the form sheet width (not pretty, I know, but it works) the value that I have been using is 540.

  2. If you really want to get it programatically. You'll have to make sure that the view has been resized and prepped for presentation before taking the bounds value from the view. I believe this happens somewhere between viewWillAppear and viewDidAppear, although I can't remember exactly.

  3. If all you want to do is ensure a button is aligned to the right, try using the autoresizingMask property of the button. I believe you'll only need to use UIViewAutoresizingFlexibleLeftMargin.

1
Bogatyr On

You can do "last minute" view setup and adjustments in viewDidLoad -- all the nib outlets have been initialized by that time.