如何在iOS中的警报按钮中创建一个功能?

时间:2015-11-27 03:48:21

标签: ios uialertview

我在didRecieveRemoteNotification方法中使用OK按钮创建了一个警报视图。单击确定按钮时有一个功能,但我调用的功能在同一个类中。如果那个函数在另一个类中怎么办?当我单击“确定”按钮时,如何调用该类。

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userPushInfo
    {
        application.applicationIconBadgeNumber = 0;
        NSDictionary *fetchedDictionary =[userPushInfo objectForKey:@"aps"];
        NSDictionary *fetchedDictionaryalert = [fetchedDictionary objectForKey:@"alert"];
        NSDictionary *fetchedDictionarybody = [fetchedDictionaryalert objectForKey:@"body"];
        NSDictionary *fetchedDictionaryactivation = [fetchedDictionarybody objectForKey:@"activation_code"];

    if(fetchedDictionaryactivation != nil)
    {
        NSDictionary *fetchedDictionaryresult = [fetchedDictionaryactivation objectForKey:@"result"];
        for (NSDictionary *user in fetchedDictionaryresult)
        {
            responseActCode = [user objectForKey:@"activation_code"];
            responseParentID = [user objectForKey:@"parent_id"];
            NSLog(@"Item actcode: %@", responseActCode);
            NSLog(@"Item parentid: %@", responseParentID);
        }
        UIAlertView *alertView = [[UIAlertView alloc]
                    initWithTitle:@"Activation Code"
                    message:(@"%@", responseActCode)
                    delegate:self
                    cancelButtonTitle: @"Ok"
                    otherButtonTitles: nil];
        [alertView show];
        alertView.tag = 0;
        NSLog(@"dadadad %@", userPushInfo);
    }
    else
    {
        NSDictionary *fetchedDictionary =[userPushInfo objectForKey:@"aps"];
        NSDictionary *fetchedDictionaryalert = [fetchedDictionary objectForKey:@"alert"];
        NSDictionary *fetchedDictionarybody = [fetchedDictionaryalert objectForKey:@"body"];
        NSDictionary *fetchedDictionaryresult = [fetchedDictionarybody objectForKey:@"result"];
        NSString *beaconID;
        for (NSDictionary *user in fetchedDictionaryresult)
        {
            beaconID = [user objectForKey:@"beacon_id"];
            mess = [user objectForKey:@"message"];
            NSLog(@"Item actcode: %@", beaconID);
            NSLog(@"Item parentid: %@", mess);
        }

        UIAlertView *alertView = [[UIAlertView alloc]
        initWithTitle:@""
        message:(@"%@", mess)
        delegate:self
        cancelButtonTitle: @"Ok"
        otherButtonTitles: nil];
        [alertView show];
        alertView.tag = 1;
        NSLog(@"dadadad %@", userPushInfo);

    }


}

1 个答案:

答案 0 :(得分:0)

要触发其他课程的功能,您可以使用:

启动视图控制器或应用代理

[[NSNotificationCenter defaultCenter] postNotificationName:@"CUSTOM_NOTIFICATION_NAME" object:nil userInfo:@{@"custom_key": @"custom_value"}];
目标类viewDidLoad

中的

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(actionDetected:) name:@"CUSTOM_NOTIFICATION_NAME" object:nil];

其中- (void)actionDetected:(NSNotification *)notif是您要触发的功能