7

Is it possible to quickly present a UIView in a UIPopoverController without having a UIViewController managing the UIView?

Currently I have a "DelegateViewController" that gets my view passed. Then I use that controller for presentation. But I'm wondering if there is an easier way?

Krumelur
  • 32,180
  • 27
  • 124
  • 263

3 Answers3

13

If you have a UIView, then you can easily create a plain UIViewController as a container.

UIViewController* controller = [[[UIViewController alloc] init] autorelease];
controller.view = myView;
bendytree
  • 13,095
  • 11
  • 75
  • 91
1

Is it possible to quickly present a UIView in a UIPopoverController without having a UIViewController managing the UIView?

No. UIPopoverController manages a view controller, not a view. When you create a popover controller, you have to provide the view controller that will manage the content. That doesn't mean that you have to create a special view controller subclass in every place where you use a popover -- as bendytree points out, you can use a plain old UIViewController if you want. But you can't just pass UIPopoverController a view -- it has no way to accept it, and wouldn't know what to do with it if did.

Caleb
  • 124,013
  • 19
  • 183
  • 272
0

It usually makes sense to have a UIViewController for a view since the controller handles all the interaction and setting up of the view. Although you can in some situations put "naked" views on screen the UIPopoverController is designed to work with a UIViewController and the ViewController paradigm is very well established and encouraged in the iOS world, so even if you think you don't seem to need a view controller it should not be harmful to have one and you might always want to extend the current functionality, right?

Please Note: If you are on iOS 5.0 creating views in Popovers is very simple and a matter of dragging-and-dropping the view controllers and hooking them up on the storyboard. Example: How to create Popovers with Xcode Storyboards

Community
  • 1
  • 1
Besi
  • 22,579
  • 24
  • 131
  • 223