0

How to create UIView in storyboard for UIBarButtonItem presenting popovercontroller. Is it possible to create separate UIView without having any UIViewController?

Requirement is that UIBarButtonitem in UIViewController when pressed should present a UIView as a popover controller, which has a UITableview in it.

Thanks for help.

user1120133
  • 3,244
  • 3
  • 48
  • 90

2 Answers2

1

If you want to present a table view, you will be better off having a table view controller, regardless how you are showing the table (popover or otherwise).

Simply setup a new view controller in storyboard, add a segue from the bar button and specify the "Style" to be Popover.

Mundi
  • 79,884
  • 17
  • 117
  • 140
1

Storyboards make this trivial, but you will need to create a new view controller for it to work. Drag a UITableViewController into your storyboard and change its size to be "Freeform".

enter image description here

Then click on the view inside of the new table view controller and change its size to something appropriate for a popover.

enter image description here

Now you can drag a connection from your UIBarButtonItem to the new view controller and set its Action Segue to be "popover"

enter image description here

You can now implement the table view functionality in a UITableViewController subclass for your new view controller and you can use -prepareForSegue: on your calling view controller to pass in any properties before the popover gets displayed.

Matt Long
  • 24,438
  • 4
  • 73
  • 99