gpt4 book ai didi

iOS 重定向回应用程序

转载 作者:行者123 更新时间:2023-11-29 02:57:30 26 4
gpt4 key购买 nike

我需要帮助,谷歌搜索也让我一无所知,因此我会在这里发帖寻求指导和帮助。

我的情况是当你按下 Ok 之后我想要应用程序 delegate.m,我想要一个简单的重定向回到另一个 View 。这可能吗?

- (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];
}

有可能吗??在他们点击取消按钮后,好吧,他们将被重定向回应用程序的特定页面???

最佳答案

试试这个:

使您的应用程序委托(delegate)符合 UIAlertViewDelegate 协议(protocol),并添加以下代码:

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

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

委托(delegate)捕获选定的按钮,检查标题,并采取相应的操作。在这种情况下,由于您位于应用程序委托(delegate)中,因此您必须手动推送 View Controller (您不在 View Controller 中,因此不允许推送)

关于iOS 重定向回应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23729165/

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