如何将值传递给具有导航 Controller 的 TableView Controller ?
我有代码来推送新的 View Controller 并使其处于事件状态,但无法将值传递给 TableView 。
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
问题是我将导航 Controller 拖到 Storyboard 上,并将其附加到表格 View 。我将该表格 View 链接到我的自定义表格 View 类。当我从名称“nav”(导航 Controller 的 Storyboard ID)实例化 View Controller 时,我得到导航 Controller 作为正在实例化的 View Controller (newTopViewController);那么如何将一个值从我实例化 View 的位置传递到 tableview Controller 呢?
最佳答案
我知道这个问题已经得到解答(做得很好),但我想我应该传递一些额外的评论。在导航 Controller 中嵌入某种类型的 View Controller 是很常见的。将标准 View Controller 包装在导航 Controller 中,然后对其进行模态转场,为您提供一个模态场景,并带有一个漂亮的导航栏来放置按钮等。此外,在 iPad 上,替换转场通常可以使用导航 Controller 。这完全取决于您如何设计事物,但如果您知道 Controller 如何堆叠以及如何轻松引用它们,您将拥有更多设计选项。这是一个片段,您可以在准备 segue 方法中使用它来轻松检测它。
if ([segue.destinationViewController isKindOfClass:[UINavigationController class]]) {
//note: have to get reference to next vc through nav controller
self.nextViewController = [[(UINavigationController*)segue.destinationViewController viewControllers]lastObject];
}
else {
self.nextViewController = segue.destinationViewController;
}
关于iphone - 使用导航 Controller Storyboard将值传递给表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15350869/