如何解决将viewController从项目导入到Swift / Objective-C中的库
我为我的应用程序提供了一些可重用性模块/选项卡。我通过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];
}
祝一切顺利。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。