gpt4 book ai didi

ios - AppDelegate 可以重定向吗?我收到错误委托(delegate)而不是方法

转载 作者:行者123 更新时间:2023-11-28 20:01:45 25 4
gpt4 key购买 nike

如果可能的话,我正在寻找应用程序委托(delegate)以重定向回主要故事,但我一直偶然发现应用程序委托(delegate)方法不起作用的错误。

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


}
}

我想知道是否可以在单击 UIAlertView 时将它们重定向回主板

最佳答案

只需在现有窗口上设置 Root View Controller 即可。您不需要创建新窗口,也不需要使其成为关键和可见的。

您可以使用 UIView transition 或 CATransition 为过渡设置动画效果(如果您喜欢的话)。

不过,这似乎是一件不寻常的尝试——您将丢失任何状态或未保存的数据,这对您的用户来说可能很奇怪。

关于ios - AppDelegate 可以重定向吗?我收到错误委托(delegate)而不是方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23731687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com