简体   繁体   中英

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

I have some reusability modules/tabs for my application. I added libraries by 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? I usually imports from "Common".

Why #import <MyApp/ExampleViewController-Swift.h> isn't working?

Below is my calling function to this ViewController. How to use bundle? 在此处输入图像描述

Ok I see there no answers. I found it myself.

If someone has a similar situation. The answer is NSNotificationCenter .

Add to your function where you want open SettingsViewController :

@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:

[[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.

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

All the best.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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