4

i have a uiview file that i embedded into my tableview header

(class TopHeader: UIView, UICollectionViewDelegate, UICollectionViewDataSource)

If I use present(_:animated:completion:) i am getting: Value of type TopHeader has no member 'present' ( self.present(MyOtherViewController(doModes: [.photo]), animated: true, completion: nil))

How can I use the present method from there? Can I call a function that is in my uiviewcontroller from this uiview file?

Duncan C
  • 128,072
  • 22
  • 173
  • 272
Tel4tel
  • 51
  • 1
  • 2
  • 9

3 Answers3

2

You can't call present(_:animated:completion) because it is a method of UIViewController, not UIView.

You shouldn't be presenting view controllers from views directly. If you need this behavior, it would be better to use a UIViewController instead of a UIView since the view controller will contain a view within it anyway.

Paolo
  • 3,825
  • 4
  • 25
  • 41
0

Can I call a function that is in my uiviewcontroller from this uiview file?

Yes, if the view is in the view controller hierarchy, you can recursively get the next responder until you reach the owning view controller.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

The present(_:animated:completion:) method is a method of UIViewController, not UIView. You need to figure out a way to pass the request to your view controller. The usual pattern is to define a protocol that lets the view as the view controller to display another view controller. Then set up your view to have the view controller as a delegate that conforms to that protocol.

Duncan C
  • 128,072
  • 22
  • 173
  • 272