问题描述
我为我的应用程序提供了一些可重用性模块/选项卡。我通过Cocoapods添加了库。我有“通用”模块,其中包含所有选项卡的通用元素,但有时需要大量依赖项导入。
是否可以ExampleViewController
从“ MyApp”导入另一个库,例如Wall?我通常从“通用”中导入。
为什么#import <MyApp/ExampleViewController-Swift.h>
不起作用?
下面是我对该ViewController的调用函数。如何使用捆绑包?
解决方法
好的,我看不到答案。我自己找到的。
如果有人有类似情况。答案是NSNotificationCenter
。
将函数添加到要打开的SettingsViewController
处:
@IBAction func userPhotoClicked(_ sender: Any) {
NotificationCenter.default.post(name: Notification.Name("profileSide"),object: nil) }
并在此ViewController(用Objective-c编写)上,在其中添加观察者的动作:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(profileSide:) name:@"profileSide" object:nil];
并删除观察者:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"profileSide" object:nil];
并在具有AddObserver和RemoveObserver的同一视图控制器上编写函数“ profileSide”。
- (void)profileSide:(NSNotification *)notification {
SettingsViewController *vc = [[SettingsViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
祝一切顺利。