iOS 重定向回应用程序

标签 ios

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

我的情况是当你按下 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/

相关文章:

android - 在 Android 和 iOS 上使用 QT 和 QML 编辑视频

iphone - 有人使用 XMPP 在 iOS 上实现推送通知吗?

iphone - 在 iPhone 中存储身份验证 token 的位置

ios - 如何使用 UIImagePickerController 相机图像来更新我的 UICollectionViewCell?

ios - 尝试分配除自身以外的委托(delegate)时出现解析错误

ios - 选择不起作用嵌入在容器 View 中的 Collection View

ios - 在解析中访问日期列 - Swift IoS 开发

iphone - writeToFile 正在覆盖以前的数据

ios - iOS 中的棕褐色调 PDF

iphone - 蓝牙应用的最佳平台