【问题标题】:Xcode Show Specific View After Local Notification本地通知后 Xcode 显示特定视图
【发布时间】:2014-03-09 11:35:48
【问题描述】:

我的应用发送本地通知,每个通知都有一个 ID。一旦用户单击其中一个通知,它应该会出现一个应该收到通知 ID 的特定视图。

例如。出现 ID 23 的通知,用户点击它,应用程序应显示屏幕“详细信息”,其中将加载 id 23 的所有信息。

所以在我的 AppDelegate 中我使用这个方法来拦截用户通知点击。

- (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

但是在这种方法中,如果我执行 segue,它就不起作用。 而是使用以下代码它几乎可以工作,但“eventDetails”视图显示为空,因为我无法将通知 ID 传递给它。

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"eventDetails"];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:navigationController];
    //[self.window setBackgroundColor:[UIColor whiteColor]];
    [self.window makeKeyAndVisible];

【问题讨论】:

    标签: ios xcode notifications views localnotification


    【解决方案1】:

    你可以试试这个方法,希望对你有用

        - (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
         // codes of Local Notification
         [self.rootviewcontroller.view addSubView:infoView];
    
    }
    

    【讨论】:

      【解决方案2】:

      找到解决方案!

      我在我的 appdelegate.m 上添加了这个:

      #import "eventDetailsController.h"
      

      并将之前的代码改成如下:

      UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
      
          eventDetailsController *edView = [[dettaglioEvento alloc] init];
          edView = [mainStoryboard instantiateViewControllerWithIdentifier:@"eventDetails"];
          edView.passedId = self.idToShow;
      
          UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:edView];
          self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
          [self.window setRootViewController:navigationController];
          //[self.window setBackgroundColor:[UIColor whiteColor]];
          [self.window makeKeyAndVisible];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-06
        • 1970-01-01
        • 2020-07-31
        • 1970-01-01
        相关资源
        最近更新 更多