UIAlertView错误未声明

时间:2014-05-19 06:08:43

标签: ios uialertview

我正在解决这个问题中的代码错误。

我的错误:使用未声明的标识符' alertView'

appdelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,UIAlertViewDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

appdelegate.m

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Daily Vibes"
                                                        message:notification.alertBody
                                                       delegate:self cancelButtonTitle:@"Okay"
                                                        otherButtonTitles:nil];
        [alert show];
    }


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

        if([title isEqualToString:@"Okay"])
        {
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            MyViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
            [(UINavigationController*)self.window.rootViewController pushViewController:vc animated:NO];
        }
    }

1 个答案:

答案 0 :(得分:1)

你错过了这个方法的近距离

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Daily Vibes"
                                                        message:notification.alertBody
                                                       delegate:self cancelButtonTitle:@"Okay"
                                                        otherButtonTitles:nil];
        [alert show];
    }
}   // <<<<----------- Here