ios - 从容器 View 以编程方式推送以查看 Controller

标签 ios objective-c collectionview

我有一个 ProfileViewController,其中有一个容器 View ,它是一个 Collection View Controller ,当在容器 View 中选择一个项目时,它将把整个 ProfileViewController 推送到 ProfileViewController 的另一个实例。这是我的代码:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:        (NSIndexPath *)indexPath {
    ProfileViewController *profileVC = [[ProfileViewController alloc] init];
    profileVC.user = self.friends[indexPath.item];
    UIViewController *parentVC = self.parentViewController;
    [parentVC.navigationController pushViewController:profileVC animated:YES];
}

然而,当它把整个 View Controller 推到黑屏上时(选项卡和导航栏仍然显示)。任何帮助如何解决这个问题?

最佳答案

您可能需要使用 nib 文件初始化 ProfileViewController,可能类似于:

ProfileViewController *profileVC = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController"bundle:nil];

字符串@"ProfileViewController"需要替换为调用此 View Controller 的任何.xib 文件。无论如何,您首先如何实例化 View Controller ?你在使用 Storyboard吗?

关于ios - 从容器 View 以编程方式推送以查看 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24269818/

相关文章:

ios - 如何在 Swift 中为 NSManagedObject 子类指定初始化器?

ios - 如何以编程方式更改 UICollectionView 单元格位置

ios - CollectionView 问题 ios swift

objective-c - 在调用 gesturerecognizers 方法之前是否存在我可以调用的任何方法?

ios - shouldChangeCharactersInRange 返回旧结果 iOS

ios - 从 Firebase 的 URL 加载图像时,CollectionsView 性能不稳定

ios - 如何查看该字符串的真实内容?

ios - PFInstallation 并添加指向 PFUser 的指针

ios - 从过滤后的搜索结果中快速删除条目

ios - Google 数据 API - 访问未配置错误