简体   繁体   English

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

[英]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.我有“通用”模块,其中包含所有选项卡的通用元素,但有时需要大量依赖导入。

Xcode

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.

相关问题 在Objective-C项目中使用Swift库 - Using Swift library in an Objective-C project Objective-C 项目中的 Swift CocoaPods 库 - Swift CocoaPods Library in Objective-C Project swift build errors from Objective-C app due to import of Objective-C static library that contains a.swift file - swift build errors from Objective-C app due to import of Objective-C static library that contains a .swift file 如何在Xcode Objective-C项目中的.mm类扩展中导入/使用快速静态库/框架 - How to import/use swift static library/framework in to .mm class extension in Xcode Objective-C Project Swift 代码中 Objective-C 中带有 id 的自定义初始化 - Custom init with id to ViewController in Objective-C from Swift code 将 iOS 框架(Swift/Objective-C)导入到 Android 应用程序项目中? - Import an iOS framework (Swift/Objective-C) into an Android app project? 无法在框架项目的 Objective-C 代码中导入 Swift 类 - Unable to import Swift class in Objective-C code in a framework project 如何在 Objective-C 项目中符合在 Swift 库中制定的协议 - How to conform a protocol made in a Swift library in a Objective-C project 在Swift项目中使用用Objective-c编写的库类 - Use library classes written in Objective-c inside Swift project 在swift项目中桥接objective-c库不起作用 - Bridging objective-c library in swift project does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM