[英]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.