繁体   English   中英

在 swift/objective-c 中将 viewController 从项目导入库

[英]Import viewController from project to library in swift/objective-c

我的应用程序有一些可重用模块/选项卡。 我通过 Cocoapods 添加了库。 我有“通用”模块,其中包含所有选项卡的通用元素,但有时需要大量依赖导入。

Xcode

可以将ExampleViewController从“MyApp”导入另一个库,例如 Wall? 我通常从“Common”进口。

为什么#import <MyApp/ExampleViewController-Swift.h>不起作用?

下面是我对这个 ViewController 的调用 function。 如何使用捆绑包? 在此处输入图像描述

好的,我看到没有答案。 我自己找到了。

如果有人有类似情况。 答案是NSNotificationCenter

添加到您想要打开SettingsViewController的 function :

@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];

并在同一个视图 controller 上写 function “profileSide”,其中您有 AddObserver 和 RemoveObserver。

- (void)profileSide:(NSNotification *)notification {
    SettingsViewController *vc = [[SettingsViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

一切顺利。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM