iOS版 - 推送通知后视图显示在接收 [英] iOS - Display view after push notification is received

查看:293
本文介绍了iOS版 - 推送通知后视图显示在接收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个应用程序的主界面是基于一个标签栏控制器。

I am working on an app whose main UI is based on a tab bar controller.

在我有一个集合视图,向下钻取通过导航控制器的详细视图选项卡中的一个。

In one of the tabs I have a collection view, which drills down to a detail view via a navigation controller.

我所试图做的是在收到一个推送通知的,我想选择这个特定的标签,从服务器获取最新的数据,找到特定项目显示,然后推详细信息视图上屏幕显示所述项目。

What I am trying to do is upon receipt of a push notification I would like to select this specific tab, fetch the latest data from the server, find the particular item to display, then push the detail view on to the screen to display said item.

我的问题是我得到以下信息后的CollectionView:didSelectItemAtIndexPath:

My problem is I get the following message after collectionView:didSelectItemAtIndexPath:

终止应用程序由于未捕获的异常'NSGenericException',
  原因:找不到赛格瑞导航控制器
  FavouriteItem。推塞格斯只能用于当源
  控制器由UINavigationController的实例进行管理。

Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'FavouriteItem'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

下面是我在做什么,到目前为止:

Here is what I am doing so far:

应用程序代表:didReceiveRemoteNotification:

App Delegate application:didReceiveRemoteNotification:

[self selectFavouritesTab];
NHFavouritesViewController *favouritesViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Favourites"];
[favouritesViewController displayFavouriteForPushNotificationWithId:favouriteId];

从FavouritesViewController - 获取最新的收藏夹之后,我发信息给displayFavouriteItemWithId:

From FavouritesViewController - After fetching the latest favourites, I send a message to displayFavouriteItemWithId:

- (void)displayFavouriteItemWithFavouriteId:(NSNumber*)favouriteId
{
    NSArray* results = [_collectionViewData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF.favouriteId == %@", favouriteId]];

    NSInteger row = [_collectionViewData indexOfObject:[results lastObject]];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
    [[self collectionView] selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];
    [self.collectionView.delegate collectionView:self.collectionView didSelectItemAtIndexPath:indexPath];
    [self performSegueWithIdentifier:@"FavouriteItem" sender:self];
}

而正是在这一点上它崩溃。我明白坠机消息说,但是我不知道是如何放置NHFavouritesViewController导航控制器内(这是嵌入到一个在故事板),当我在应用程序委托的推送通知应对?

And it is at this point it crashes. I understand what the crash message is saying, however what I don't know is how to place NHFavouritesViewController inside a navigation controller (which is embedded inside one in the storyboard) when I respond to the push notification in the app delegate?

推荐答案

您可以在一个标准的导航控制器换一个视图控制器:

You can wrap a view controller in a standard navigation controller with:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:favouritesViewController];

但我无法从你的code以上favouritesViewController是如何在tabBarController psented $ P $看看。如果您在故事板做,那么只需将一个空白导航控制器,勾你tabBarController到导航控制器(按住Ctrl键的相关标签,然后选择关系赛格瑞:viewControllers,然后从导航控制器挂钩您FavouritesViewController(同样)。

But I can't see from your code above how favouritesViewController is presented in the tabBarController. If you are doing it in a storyboard, then just drag in a blank navigation controller, hook the relevant tab of your tabBarController to the navigation controller (Ctrl-drag, then select "Relationship segue: viewControllers", and then hook from the navigation controller to your FavouritesViewController (likewise).

编辑:

如果已在故事板完成的,那么你就需要修改你的code皮卡 NHFavouritesViewController ,而不是新实例的现有版本。像(假设你在 self.tabBarController 你的标签栏控制器的引用,而 favouritesViewController 的东西是在索引标签 favouritesTab (我假设你可以得到这些,因为你已经选择标签的方法):

If that is already done in the storyboard, then you need to amend your code to pickup the existing version of NHFavouritesViewController, instead of instantiating new. Something like (assuming you have a reference to your Tab Bar Controller in self.tabBarController, and the favouritesViewController is in the tab with index favouritesTab (I assume you can get these, since you already have a method to select the tab):

UINavigationController *navController = (UINavigationController *)self.tabBarController.viewControllers[favouritesTab];
NHFavouritesViewController *favouritesViewController = (NHFavouritesViewController *) navController.rootViewController;

这篇关于iOS版 - 推送通知后视图显示在接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆