gpt4 book ai didi

iOS - 收到推送通知后显示 View

转载 作者:行者123 更新时间:2023-11-29 10:37:29 24 4
gpt4 key购买 nike

我正在开发一个主 UI 基于标签栏 Controller 的应用。

在其中一个选项卡中,我有一个 Collection View ,它通过导航 Controller 向下钻取到详细 View 。

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

我的问题是我在 collectionView:didSelectItemAtIndexPath: 之后收到以下消息:

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.'

这是我目前所做的:

应用委托(delegate)应用程序:didReceiveRemoteNotification:

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

从 FavouritesViewController - 获取最新的收藏夹后,我向 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];
}

就在此时它崩溃了。我明白崩溃消息在说什么,但是我不知道当我响应应用程序委托(delegate)中的推送通知时如何将 NHFavouritesViewController 放置在导航 Controller 中(它嵌入在 Storyboard 中的一个 Controller 中)?

最佳答案

您可以将 View Controller 包装在标准导航 Controller 中:

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

但我无法从您上面的代码中看出 favouritesViewController 是如何在 tabBarController 中呈现的。如果你在 Storyboard中这样做,那么只需拖入一个空白的导航 Controller ,将 tabBarController 的相关选项卡挂接到导航 Controller (Ctrl-拖动,然后选择“Relationship segue:viewControllers”,然后从导航 Controller Hook 到您的 FavouritesViewController(同样)。

编辑:

如果这已经在 Storyboard中完成,那么您需要修改代码以获取 NHFavouritesViewController 的现有版本,而不是实例化新版本。类似于(假设您在 self.tabBarController 中引用了您的 Tab Bar Controller,并且 favouritesViewController 在索引为 favouritesTab 的选项卡中(我假设您可以获得这些,因为您已经有了选择选项卡的方法):

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

关于iOS - 收到推送通知后显示 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26191685/

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