- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个 UICollectionView
,当用户按下一个单元格时,我会使用 Storyboard在 UINavigationController
中呈现另一个 View Controller 。
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"editBookIPad"
sender:indexPath];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue
sender:(id)sender
{
// Did not include code for other segues, but I check which is the current one properly
UINavigationController *dest = segue.destinationViewController; // This is nil!
dest.modalPresentationStyle = UIModalPresentationFormSheet;
DetailsViewController *detailsVC = (id)[dest topViewController];
detailsVC.stack = self.stack;
detailsVC.editingMode = 1;
detailsVC.bookToEdit = [self.fetchedResultsController objectAtIndexPath:sender];
[self.collectionView deselectItemAtIndexPath:sender
animated:YES];
}
现在,我的问题是 segue.desinationViewController
返回 nil
(如代码片段中的注释所说)。
只是为了调试,我将 UINavigationController
更改为另一个 View Controller ,我没有遇到任何问题。我不知道从模式更改为推送作为过渡样式是否有帮助,因为不可能推送 UINavigationController
(发生崩溃时说是这样)。
我清理了项目和构建文件夹并重新启动了我的计算机(以及 Xcode)。
这是运行应用程序时的样子:
在搜索类似问题时,我一无所获。大多数其他问题是关于在目标 View Controller 上设置的属性为 nil(例如 this )。
我使用 Xcode 5.1.1 并将 iOS 7.0 作为开发目标。
编辑1
同样的问题现在发生在我的应用程序的所有部分(UINavigationController
以模态方式呈现的所有地方)。 然而,它只在某些情况下发生,但每次 segue.destinationViewController
仍然是 nil
。
编辑2
我用这个替换了 prepareForSegue
代码(手动完成):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard"
bundle:nil];
UINavigationController *navCon = [storyboard instantiateViewControllerWithIdentifier:@"AllBooksVCDetails"]; // The problematic navigation controller
navCon.modalPresentationStyle = UIModalPresentationFormSheet;
BKSBookDetailsViewController *detailsVC = (id)[navCon topViewController];
detailsVC.stack = self.stack;
detailsVC.editingMode = 1;
detailsVC.bookToEdit = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self presentViewController:navCon
animated:YES
completion:nil];
[self.collectionView deselectItemAtIndexPath:indexPath
animated:YES];
这行得通。所以我认为问题出在 Storyboard中。
最佳答案
我在将 View Controller 嵌入 NavigationController 时遇到了同样的问题。
override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destinationVC = segue.destinationViewController as! UINavigationController
let nextViewController = destinationVC.viewControllers[0] as! SecondViewController
nextViewController.someProperty = someValue
}
此链接对我有帮助:
关于ios - 呈现 UINavigationController 模态时,segue.destinationViewController 为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30695367/
我来自 Asp.Net 世界,试图理解 Angular State 的含义。 什么是 Angular 状态?它类似于Asp.Net中的ascx组件吗?是子页面吗?它类似于工作流程状态吗? 我听到很多人
我一直在寻找 3 态拨动开关,但运气不佳。 基本上我需要一个具有以下状态的开关: |开 |不适用 |关 | slider 默认从中间开始,一旦用户向左或向右滑动,就无法回到N/A(未回答)状态。 有人
我是一名优秀的程序员,十分优秀!