簡體   English   中英

iOS使用AppDelegate.m中ViewController.m中的方法嗎?

[英]IOS Using method from ViewController.m in AppDelegate.m?

所以我在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

您可以在視圖控制器中注冊以接收通知,以在應用程序進入后台時收到通知:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM