简体   繁体   English

AppDelegate可以重定向?我收到错误委托而不是方法

[英]AppDelegate can redirect??I'm getting error delegate not method

I'm looking for the app delegate to redirect back to the main story if that is possible but i kept on stumble upon error that app delegate method doesn't work. 我正在寻找可能的应用程序委托重定向到主要故事,但我不断发现应用程序委托方法不起作用的错误。

AppDelegate.h AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,UIAlertViewDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

AppDelegate.m 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];
            UIViewController *mainViewController = [storyboard instantiateInitialViewController];
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            self.window.rootViewController = mainViewController;
            [self.window makeKeyAndVisible];


        }
    }

I'm wondering is it possible to redirect them back to the main board when the click the UIAlertView 我想知道当单击UIAlertView时是否可以将它们重定向回主板

Just setting the root view controller on the existing window should do it. 只需在现有窗口上设置根视图控制器即可。 You don't need to create a new window, and you don't need to make it key and visible. 您无需创建新窗口,也无需使其成为关键且可见。

You can animate the transition by using UIView transition or CATransition if you want to get fancy. 如果您想花哨的话,可以使用UIView transition或CATransition为过渡设置动画。

This does seem like an unusual thing to attempt, though - you'll lose any state or unsaved data and it might be quite odd for your user. 但是,这似乎是一件很不寻常的事情-您会丢失任何状态或未保存的数据,这对您的用户来说可能很奇怪。

if you want to present a view controller try something like the following: 如果要显示视图控制器,请尝试以下操作:

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

    if([title isEqualToString:@"Okay"])
    {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *vc = [storyboard instantiateInitialViewController];
        [self.window.rootViewController presentViewController:vc animated:YES completion:nil]

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在AppDelegate中初始化委托,但可以在类方法中初始化 - Can't initializing a delegate in the AppDelegate but inside a class method it works appDelegate可以成为模式视图委托吗? - Can appDelegate be a modal view delegate? 我可以在AppDelegate.m中注销NSNotificationCenter吗? - Can i unregister NSNotificationCenter inside AppDelegate.m? 我可以在AppDelegate.m之外注册推送通知吗? - Can I Register for Push Notifications Outside of AppDelegate.m? 如何在AppDelegate中触发navigationController:willShowViewController委托方法 - How to trigger navigationController:willShowViewController delegate method in AppDelegate 从Appdelegate触发ViewController中的委托方法 - Triggering delegate method in ViewController from Appdelegate appDelegate方法中发生错误 - Error occurred in appDelegate method 通过按钮操作在AppDelegate中调用方法时出错。 - Getting error when calling method in AppDelegate from a button action. CAPS Pagemenu:willMoveToPage委托方法出错 - CAPS Pagemenu : willMoveToPage delegate method getting error 如果我调用此方法,那么我将收到一个错误消息,即“数据库已锁定”。我该如何解决呢? 请帮我 - If i call this method,then i'm getting a error which is “database is lock”.How i can solve this?? Please help me
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM