Ios 从目标C文件调用目标C函数

Ios 从目标C文件调用目标C函数,ios,Ios,我正在尝试从AppDelegate.m的applicationWillResignActive函数调用GameViewController.mm的tearDownGL函数 如何从AppDelegate.m访问GameViewController.mm的函数 这是我的GameViewController.h文件: #ifndef gameviewcontroller_h #define gameviewcontroller_h #import <UIKit/UIKit.h> #imp

我正在尝试从AppDelegate.m的applicationWillResignActive函数调用GameViewController.mm的tearDownGL函数

如何从AppDelegate.m访问GameViewController.mm的函数

这是我的GameViewController.h文件:

#ifndef gameviewcontroller_h
#define gameviewcontroller_h

#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>



@interface GameViewController : GLKViewController

@end



#endif

事实证明,我需要添加

@interface GameViewController : GLKViewController
- (void)tearDownGL;
- (void)setupGL;
@end
转到GameViewController.h,并使用AppDelegate.m中的以下代码进行调用:

GameViewController *vc = [[GameViewController alloc]init];
[vc setupGL];

调用
dealloc
是非法的-另外,请在问题中的此处显示您的代码。您压缩github代码的原因是否充分?将其置于git版本控制之下,并将其作为代码上传到github。您永远不应该直接调用dealloc。谢谢。我已经编辑了原始帖子,以调用teardownGL函数而不是dealloc。我已经在帖子中包含了源代码。
#include "AppDelegate.h"
#include "GameViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {




    NSLog(@"applicationWillResignActive");


    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    NSLog(@"applicationDidEnterBackground");
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {


        NSLog(@"applicationWillEnterForeground");
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    NSLog(@"applicationDidBecomeActive");


    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {

        NSLog(@"applicationWillTerminate");






    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}









@end
@interface GameViewController : GLKViewController
- (void)tearDownGL;
- (void)setupGL;
@end
GameViewController *vc = [[GameViewController alloc]init];
[vc setupGL];