Objective c 从AppDelegate调用方法无法识别的选择器发送到实例错误

Objective c 从AppDelegate调用方法无法识别的选择器发送到实例错误,objective-c,appdelegate,Objective C,Appdelegate,我正在尝试调用AppDelegate.m中另一个类的方法。我已经做了以下工作: 在MyClass.h中,我有-void testMethod 在AppDelegate.m中,我有 #导入“MyClass.h” MyClass*myClassInstance=[[MyClass alloc]init] [myClassInstance测试方法] 在AppDelegate.h中,我还导入了 #导入“MyClass.h” 我想我已经做了回答这个问题的所有建议: 但我仍然收到“无法识别的选择器发送到实例

我正在尝试调用AppDelegate.m中另一个类的方法。我已经做了以下工作:

  • 在MyClass.h中,我有
    -void testMethod
  • 在AppDelegate.m中,我有
    #导入“MyClass.h”

    MyClass*myClassInstance=[[MyClass alloc]init]
    [myClassInstance测试方法]
  • 在AppDelegate.h中,我还导入了
    #导入“MyClass.h”
  • 我想我已经做了回答这个问题的所有建议:

    但我仍然收到“无法识别的选择器发送到实例”错误

    少了什么


    提前谢谢

    尝试将方法调用放入某些appDelegate生命周期方法中,如:

     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
         // Override point for customization after application launch.    
         Test* testObject = [[Test alloc] init];
         [testObject testMethod];  
         return YES;
     }
    
    对于要实例化的类,请使用以下内容:

    Test.h文件

     #import <Foundation/Foundation.h>
    
     @interface Test : NSObject
    
     -(void)testMethod;
    
     @end
    

    在这种情况下,当应用程序初始化时,控制台上会显示日志消息。

    使用完整准确的错误消息更新您的问题。您遗漏了消息的导入部分。用导致错误的确切代码行更新您的问题。您是否忘记在void周围添加括号?例如,-(void)testMethod@Ke您需要在m文件中实现此方法。检查本教程
     #import "Test.h"
    
     @implementation Test
    
    
     -(void)testMethod{
         NSLog(@"test");
     }
    
     @end