IOS 使用 AppDelegate.m 中 ViewController.m 的方法?

     2023-02-23     92

关键词:

【中文标题】IOS 使用 AppDelegate.m 中 ViewController.m 的方法?【英文标题】:IOS Using method from ViewController.m in AppDelegate.m? 【发布时间】:2013-07-09 16:46:48 【问题描述】:

所以我在 ViewController.m 中有一个方法,只需按一下按钮即可发布通知(到通知中心)

这是 ViewController.m 中的方法

- (IBAction)buttonPush:(id)sender 
    //clear NC
    [[UIApplication sharedApplication] cancelAllLocalNotifications];


    //make mutablearray
    NSMutableArray *list = [NSMutableArray array];


    [list addObject:first];
    [list addObject:second];
    [list addObject:third];



    //post notification
    for (UITextField *thing in list) 
        UILocalNotification *notif = [[UILocalNotification alloc] init];
        notif.alertBody = thing.text;
        [[UIApplication sharedApplication] presentLocalNotificationNow:notif];
        NSLog(@"looped!");

    


    

我想做的是在以下方法中使用上述方法(在 AppDelegate.m 中):

- (void)applicationDidEnterBackground:(UIApplication *)application

【问题讨论】:

你在使用故事板吗? @jsd 是的,我使用了一个“Touch Down”引用按钮的插座 【参考方案1】:

您可以注册以在您的视图控制器中接收通知,以便在应用程序进入后台时收到通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buttonPush:) name:UIApplicationWillResignActiveNotification object:nil];

【讨论】:

好的,但我会把这个放在哪里?在 - (void)applicationDidEnterBackground:(UIApplication *)application ? 没有。在 ViewController.m 中的 -(void)viewDidLoad 方法中。

AppDelegate.m 和 View Controller.m 的区别

】AppDelegate.m和ViewController.m的区别【英文标题】:DifferencebetweenAppDelegate.mandViewController.m【发布时间】:2011-05-1917:33:50【问题描述】:谁能告诉我在iPhone编程过程中何时使用AppDelegate.m和AppDelegate.h?我只使用ViewController.m和ViewControll... 查看详情

未修改的 AppDelegate.m 中的编译错误

】未修改的AppDelegate.m中的编译错误【英文标题】:CompileErrorsinuntouchedAppDelegate.m【发布时间】:2013-01-0420:17:37【问题描述】:我一直在创建一个简单的示例应用程序来演示在IOS中播放声音文件。为此,我创建了一个带有一个视图... 查看详情

如何在 AppDelegate 中执行 Segue?

】如何在AppDelegate中执行Segue?【英文标题】:HowtoperformSegueinAppDelegate?【发布时间】:2012-08-3114:25:51【问题描述】:我正在尝试使用Storyboard在IOS5.1上完成应用程序。基本上我正在做一个保管箱应用程序。因为我使用的是DropboxSDK... 查看详情

AppDelegate.m 文件中的两个包冲突

】AppDelegate.m文件中的两个包冲突【英文标题】:TwopackagesconflictinAppDelegate.mfile【发布时间】:2017-04-2315:12:05【问题描述】:我在我的项目中使用https://github.com/devfd/react-native-google-signin和https://github.com/luisfcofv/react-native-deep-linking包... 查看详情

在 AppDelegate.m 中使用未声明的标识符“对讲机”-react-native-intercom

】在AppDelegate.m中使用未声明的标识符“对讲机”-react-native-intercom【英文标题】:Useofundeclaredidentifier\'Intercom\'inAppDelegate.m-react-native-intercom【发布时间】:2021-06-2020:36:15【问题描述】:我正在使用react-native-intercom在我的应用程序... 查看详情

IOS - 使用 FirebaseDynamicLinks 的问题

...同样的问题还在构建设置“OtherLinkerFlag”中添加了-ObjC在AppDelegate.m中导入#import"AppDelegate.h"#import"F 查看详情

AppDelegate.m 的“application:didFinishLaunchingWithOptions”的默认实现是不是从 iOS 6 更改为 iOS 8?

】AppDelegate.m的“application:didFinishLaunchingWithOptions”的默认实现是不是从iOS6更改为iOS8?【英文标题】:DidAppDelegate.m\'sdefaultimplementationfor\'application:didFinishLaunchingWithOptions\'changefromiOS6toiOS8?AppDelegate.m的“applicatio 查看详情

AppDelegate.swift 如何在 Xcode 6.3 中替换 AppDelegate.h 和 AppDelegate.m

】AppDelegate.swift如何在Xcode6.3中替换AppDelegate.h和AppDelegate.m【英文标题】:HowdoesAppDelegate.swiftreplaceAppDelegate.handAppDelegate.minXcode6.3【发布时间】:2015-05-2203:49:52【问题描述】:根据iOSDeveloperLibrary应用委托是您编写自定义应用级代码... 查看详情

从 AppDelegate.m 中的 applicationDidEnterBackground 中去掉键盘

】从AppDelegate.m中的applicationDidEnterBackground中去掉键盘【英文标题】:GetridofthekeyboardfromapplicationDidEnterBackgroundintheAppDelegate.m【发布时间】:2012-02-0714:53:47【问题描述】:我的MainViewController.m文件中有一个带有文本字段的应用程序。... 查看详情

AppDelegate.m (Cordova 2.3.0) 中不存在 didFinishLaunchingWithOptions 方法

】AppDelegate.m(Cordova2.3.0)中不存在didFinishLaunchingWithOptions方法【英文标题】:didFinishLaunchingWithOptionsmethoddoesnotexistinAppDelegate.m(Cordova2.3.0)【发布时间】:2014-01-2919:31:55【问题描述】:我们的应用是使用Cordova/Phonegap为iOS构建的,我们... 查看详情

如何在 AppDelegate.m 中获取现有的 UIViewController(不是 rootviewcontroller)?

】如何在AppDelegate.m中获取现有的UIViewController(不是rootviewcontroller)?【英文标题】:HowtogetanexistingUIViewController(notrootviewcontroller)inAppDelegate.m?【发布时间】:2014-08-2005:38:05【问题描述】:在我的AppDelegate.m中,我想获取情节提要... 查看详情

仅为 AppDelegate.m iOS 中的首次启动设置特定方向

】仅为AppDelegate.miOS中的首次启动设置特定方向【英文标题】:SetspecificorientationonlyforfirstlaunchinAppDelegate.miOS【发布时间】:2019-09-3017:18:16【问题描述】:我将这个库用于我的reactnative项目:react-native-orientation-locker我想要实现的是... 查看详情

来自 appDelegate 的 javascript 调用:phonegap iOS

】来自appDelegate的javascript调用:phonegapiOS【英文标题】:javascriptcallfromappDelegate:phonegapiOS【发布时间】:2011-10-2009:13:56【问题描述】:我如何在appDelegate.m类中获得phonegapwebview的实例我想在通知接收上调用javascript函数(即来自appDel... 查看详情

将 AppDelegate.h 和 AppDelegate.m 替换为 AppDelegate.swift

】将AppDelegate.h和AppDelegate.m替换为AppDelegate.swift【英文标题】:ReplaceAppDelegate.handAppDelegate.mtoAppDelegate.swift【发布时间】:2015-06-0212:52:02【问题描述】:我只有一个Objective-C项目,我想使用AppDelegate访问我的xcdatamodel,但是当我将AppD... 查看详情

无法从 appdelegate.m 为 NSProgressIndicator 设置动画

】无法从appdelegate.m为NSProgressIndicator设置动画【英文标题】:UnabletoanimateNSProgressIndicatorfromappdelegate.m【发布时间】:2013-12-1121:03:29【问题描述】:我之前在IOS上工作过,但刚刚开始在MacOsX可可应用程序上工作。我遇到了关于NSProgr... 查看详情

将案例编码到 appDelegate 文件中[关闭]

】将案例编码到appDelegate文件中[关闭]【英文标题】:Thecase(s)codingintoappDelegatefile[closed]【发布时间】:2013-01-2821:55:23【问题描述】:我有一个关于iOS开发的问题;iPhone/iPad。我需要在AppDelegate.m/h文件中编码的情况是什么?我可以... 查看详情

iOS AppDelegate.m:处理 openUrl RCTLinkingManager 和 Twitter - 方法 'application:openURL:options:' 的重复声明

】iOSAppDelegate.m:处理openUrlRCTLinkingManager和Twitter-方法\\\'application:openURL:options:\\\'的重复声明【英文标题】:iOSAppDelegate.m:HandlingopenUrlRCTLinkingManagerandTwitter-Duplicatedeclarationofmethod\'application:openURL:options 查看详情

如何从 AppDelegate.m 调用 ViewController.m 方法

】如何从AppDelegate.m调用ViewController.m方法【英文标题】:HowtocallaViewController.mmethodfromtheAppDelegate.m【发布时间】:2014-01-2517:09:35【问题描述】:在我的ViewController.m中,我有无效的“保存数据”:#import"ViewController.h"@interfaceViewControll... 查看详情