Apple推送通知的App Delegate调用不提供viewcontroller

时间:2015-07-06 05:29:13

标签: ios objective-c iphone

我已将Apple推送通知嵌入到我的应用中。弹出通知时,我会看到一个警报视图,当单击视图时,我会导航到一个Details控制器。但是,在单击视图按钮后,它不会执行任何操作并冻结应用程序。这是我在警报视图中打开详细信息的代码点击:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:@"Details" bundle:nil];

RearTableViewController *rearView = [[RearTableViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];

SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
                                                initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];

mainRevealController.delegate = self;
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
[self.window makeKeyAndVisible];

提前致谢!

2 个答案:

答案 0 :(得分:1)

//Don't realloc self.window.
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:@"Details" bundle:nil];


//Alloc this VC with nib name like initWithNibNamed:bundle:
RearTableViewController *rearView = [[RearTableViewController alloc]initWithNibName:@"RearTableViewController" bundle:nil];
    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];

SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
                                                initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];

mainRevealController.delegate = self;
if(self.window.rootViewController){
      [self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
}
else{
     self.window.rootViewController = mainRevealController;
}
  [self.window makeKeyAndVisible];

希望它能奏效。

答案 1 :(得分:0)

删除以下代码。

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

无需再次分配窗口。如果这样做,则必须再次设置rootViewController。