我有包含两个导航控制器,其被嵌入视图控制器的页面视图控制器。
是否有可能直接从视图控制器将数据传递到页面视图控制器。我想用委托模式,但我觉得那么我应该再次委托给导航控制器首先委托给页面视图控制器。有谁知道一个更简单的解决方案?
提前致谢!
我不认为是明智的,在这里使用的协议,你潜水太深了,是不是可以使用的通知?
在你认为应该调用委托函数:
NotificationCenter.default.post(name: Notification.Name("yourNotification"), object: your object)
然后在您的uipageViewController viewDidLoad中:
NotificationCenter.default.addObserver(self, selector: #selector(yourFuncName), name: NSNotification.Name("yourNotification"), object: nil)
在viewDidLoad中从“PageViewController”,加
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FooBar) name:@"FooBar" object:nil];
}
- (void) FooBar {
NSLog(@"Foo");
};
然后从“视图控制器”呼
[[NSNotificationCenter defaultCenter] postNotificationName:@"FooBar" object:nil];