简体   繁体   English

如何在NSObject类中快速引用viewcontroller?

[英]How to take reference of viewcontroller in NSObject class in swift?

我的要求是我在NSObject类中声明了一个函数,我想在一个firstviewcontroller中使用该函数,假设如果我想再次在secondviewcontroller中使用该函数,firstviewcontroller会调用我如何在NSObject类中划分这两个viewcontrollers的人,可以告诉我吗?

You can implement same function in both viewcontrollers with the implementation of protocol. 您可以通过协议的实现在两个视图控制器中实现相同的功能。 And you can get reference of one viewcontroller in other view controller by using class level method which will return instance of that view controller. 通过使用类级别的方法,您可以获取另一个视图控制器中一个视图控制器的引用,该方法将返回该视图控制器的实例。

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

相关问题 如何在NSObject类和ViewController之间切换 - How to switch between NSObject Class to ViewController 如何将viewcontroller连接到NSObject类文件? - How to connect viewcontroller to NSObject class file? 如何从iOS中的NSObject类导航到ViewController? - How to navigate to a ViewController from NSObject Class in iOS? 从派生自 NSObject 的 Swift class 呈现一个 ViewController? - present a ViewController from a Swift class derived from an NSObject? 如何在同一ViewController中初始化两个NSObject实例-Swift - How Do I Initialize Two Instances of NSObject in the same ViewController - Swift Swift:将值从一个类传输到另一个类或从 ViewController 类到 NSObject 的特定值 - Swift: Transfer value from one class to another or to be specific from ViewController class to NSObject 如何将swift类导入到ViewController中? - How to lmport swift class into ViewController? 从NSObject类调用ViewController方法 - Call a ViewController method from NSObject Class iOS从我的viewController访问NSObject类 - iOS accessing NSObject class from my viewController 当单击 Swift 中 NSObject 内部的 tableView 中的项目时,如何在 NSObject Class 内部的 UIViews 或 UIViewController 之间正确切换? - How to switch properly between UIViews or UIViewController inside NSObject Class when clicked the item in tableView inside of NSObject in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM