1

I actually work on a app in Swift. I have my main ViewController with a ScrollView only.

In my swift file i add 3 view (3 subview controller) into the ScrollView in order to have a special navigation (horizontal navigation like a View Pager).

The main ViewController with his subviews

The problem is that each view has his swift file and therefore i don't find the solution to communicate with the ScrollView of the main ViewController from a subview.

For example a SubViewController (one of the three) have button on it. And i would put a listener on this button and On click move the position of the screen in the ScrollView (which is on the main view controller), thanks to the method setContentOffset of the scrollview.

iRiziya
  • 3,235
  • 1
  • 22
  • 36
nekflamm
  • 131
  • 12

1 Answers1

3

You should use delegate or an NSNotificationCenter In order to pass a notification/delegate to other view in your case UIScrollView. In you UIScrollView you should implement the delegation methods. and Whooala, your UIView notified the UIScrollView of something you want it to know.

Here is example of the usage Delegates in swift?

And here is some documentations https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html

And a tutorial http://code.tutsplus.com/tutorials/swift-from-scratch-delegation-and-properties--cms-23445

Community
  • 1
  • 1
Coldsteel48
  • 3,482
  • 4
  • 26
  • 43