[英]Import viewController from project to library in swift/objective-c
I have some reusability modules/tabs for my application.我的应用程序有一些可重用模块/选项卡。 I added libraries by Cocoapods.我通过 Cocoapods 添加了库。 I have "Common" module where it contains common elements for all tabs, but sometimes requires a lot of dependent imports.我有“通用”模块,其中包含所有选项卡的通用元素,但有时需要大量依赖导入。
It's possible to ExampleViewController
import from "MyApp" to another library for example Wall?可以将ExampleViewController
从“MyApp”导入另一个库,例如 Wall? I usually imports from "Common".我通常从“Common”进口。
Why #import <MyApp/ExampleViewController-Swift.h>
isn't working?为什么#import <MyApp/ExampleViewController-Swift.h>
不起作用?
Below is my calling function to this ViewController.下面是我对这个 ViewController 的调用 function。 How to use bundle?如何使用捆绑包?
Ok I see there no answers.好的,我看到没有答案。 I found it myself.我自己找到了。
If someone has a similar situation.如果有人有类似情况。 The answer is NSNotificationCenter
.答案是NSNotificationCenter
。
Add to your function where you want open SettingsViewController
:添加到您想要打开SettingsViewController
的 function :
@IBAction func userPhotoClicked(_ sender: Any) {
NotificationCenter.default.post(name: Notification.Name("profileSide"), object: nil) }
and on this ViewController (was written in Objective-c) where the action add observer:在这个 ViewController(用 Objective-c 编写)上添加观察者的动作:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(profileSide:) name:@"profileSide" object:nil];
and remove observer:并删除观察者:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"profileSide" object:nil];
and write function "profileSide" on this same view controller where you have AddObserver and RemoveObserver.并在同一个视图 controller 上写 function “profileSide”,其中您有 AddObserver 和 RemoveObserver。
- (void)profileSide:(NSNotification *)notification {
SettingsViewController *vc = [[SettingsViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
All the best.一切顺利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.