从另一个视图访问ViewController的ScrollView

时间:2015-07-16 09:16:33

标签: ios xcode swift scrollview subview

我实际上在Swift处理一个应用。 我的主ViewController只有ScrollView

在我的swift文件中,我将3个视图(3个子视图控制器)添加到ScrollView中,以便进行特殊导航(水平导航,如View Pager)。

The main ViewController with his subviews

问题是每个视图都有他的快速文件,因此我找不到与ScrollView的主ViewController的{​​{1}}进行通信的解决方案。< / p>

例如,subview(三个中的一个)上有按钮。 我会在这个按钮上放置一个监听器,然后点击移动SubViewController(位于主ScrollView上)屏幕的位置,这要归功于view controller的方法{ {1}}。

1 个答案:

答案 0 :(得分:3)

您应该使用delegateNSNotificationCenter 要将notification / delegate传递给您案例UIScrollView中的其他视图。 在您UIScrollView中,您应该实现委派方法。 和Whooala,您的UIView通知了UIScrollView您想要了解的内容。

以下是用法示例 Delegates in swift?

这是一些文件 https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html

还有一个教程 http://code.tutsplus.com/tutorials/swift-from-scratch-delegation-and-properties--cms-23445

相关问题