【问题标题】:how to call the method one class to another class in obj c如何在obj c中将一个类的方法调用到另一个类
【发布时间】:2015-04-12 23:26:26
【问题描述】:

我有一个 appdelegate 和 notifyviewcontroller 类。

声明一种方法-(void)getNotificaionform in notifyviewcontroller

我想在appdelegate applicationDidBecomeActiveapplicationDidEnterBackground中调用这个方法。

我怎样才能做到这一点对我有帮助?

我是开发新手。

【问题讨论】:

标签: ios objective-c iphone


【解决方案1】:
for (UIViewController * vc in Nvc.viewControllers) {
    if ([vc isKindOfClass:notifyviewcontroller Class]) {
        [vc getNotificaionform];
    }
}

在您的 applicationDidEnterBackground 中使用此代码,这里 Nvc 是 UINavigationController 的一个对象。

【讨论】:

    【解决方案2】:

    为了让您 appDelegate 了解您的 UIViewController 子类,您必须导入其标头。

    所以在你的 AppDelegate.m 添加 -

    #import "NotifyViewController.h"
    

    然后假设您的 rootViewController 属于此类,您可以在 AppDelegate.m 中的任何位置访问它并使用 -

    向其发送消息
    [(NotifyViewController*)self.window.rootViewController importNotificationForm];// I changed the method name slightly as I don't like to use get with a method of type void
    

    注意类型转换,并且请以大写字母开头类名并使用驼峰式大小写。遵循命名约定以便于阅读代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      • 2021-04-02
      相关资源
      最近更新 更多