- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码目前是这样的:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let des = segue.destinationViewController as? AURReportViewController {
des.currentType = currentType
}
if let des = segue.destinationViewController as? AURAddBeanViewController {
des.currentType = currentType
}
}
有没有办法同时在 UIViewController
之一中进行 make as?
?
if let des = segue.destinationViewController as? (AURReportViewController || AURAddBeanViewController) {
des.currentType = currentType
}
最佳答案
不,没有。这两种类型不会相互继承。 Swift 是强类型的。在您的提案中,if let
内, des
可以是两种不同类型之一。编译器未设置为处理“在此 block 中此变量可能是 AURAddBeanViewController 或可能是 AURReportViewController(或者可能是...等)”的情况。编译器想要确切地知道每个变量是什么类型。
现在如果每个类都符合共享协议(protocol)HasCurrentType
,编译器可以理解“在这个 block 中,这个变量符合 HasCurrentType”。类型安全规则得到遵守,编译器很高兴。
苹果文档protocol conformance testing在“检查协议(protocol)一致性”部分中,示例名为 HasArea
。所以在你的情况下,if let des = segue.destinationViewController as? HasCurrentType
...
关于swift - 有什么方法可以使 segue.destinationViewController 成为?判断 UIViewController 之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33749536/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isE
有没有办法更改 segue 将在准备 segue 时调用的 Controller ?当使用嵌入式 segue 更改 segmentedcontrol 时,我正在尝试这样做。谢谢! 最佳答案 您可能已经
我正在使用 Spotify API 开发一个 Storyboard应用。我使用这个 ( https://github.com/avazquezpr/SpotifyDemo ) Github 项目作为“
我的应用程序中的 UITableView 是使用 NSFetchedResultsController 进行管理的,我想实现主从行为,但每次我点击单元格时都会收到此 -[UIViewControlle
嘿伙计们,这行代码是做什么的? AddRoleTVC *addRoleTVC = segue.destinationViewController; 我知道第一部分,AddRoleTVC
我试图让我的应用程序同时适用于 iOS7 和 iOS8,但我在 View Controller 中的 prepareForSegue 方法中遇到了问题。 在 iOS8 中 segue.destinat
我正在使用 John Lluch 的 SWRevealViewController这很好用,除了我不知道如何在目标 View Controller 中设置选择器,就像我在其他 UIViewContro
下午好! 我对 Swift 比较陌生,虽然我认为我已经设法解决了大部分问题,但是我在间接设置 segue 的 destinationViewController 时遇到困难。 我知道 destinat
我刚刚意识到下面的代码总是创建一个新的 TagsFeedViewController。这是segues的默认行为吗?有没有办法将 iOS 配置为不每次都创建新的 destinationViewCont
我试图在我的 prepareForSegue 方法中将一个 NSManagedObjectContext 从一个 View Controller 传递到下一个 View Controller ,但我无
我有一个按钮正在连接到一个新的 viewController。当我按下按钮时,在新 View Controller 出现之前会有 3-4 秒的可见延迟。我读过关于 stackoverflow 的其他问
奇怪的问题: 我创建了一个带有两个 View Controller 的 Storyboard,并与自定义转场(交叉溶解)相连。我通过以下方式实现 segue: -(void)transitionToI
我想通过 segue 将我的 View Controller “滑出”到 destinationViewController 上方。这是我的代码: override func perform() {
所以我有一个像这样的 prepareForSegue 方法: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyOb
我有一个带有三个选项卡的 UITabBarController:每个选项卡都是一个嵌入了 View Controller 的导航 Controller 。目前 tabController 是初始 Vi
我已将 UILongPressGestureRecognizer 添加到我的 UICollectionViewCell 并创建了一个转场,因此通过长按一个 cell 用户转场到一个 View Cont
我已经编写了一个自定义 segue 来获得淡入淡出效果,我试图通过将 destination view controller 插入 source view controller 并设置动画来实现sou
我的代码目前是这样的: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if
我已经构建了一个侧面菜单,当您单击栏按钮项目时会弹出,单击菜单选项之一后, View Controller 会加载正确的数据,但栏按钮项消失。所以我做了一些研究我发现问题是我的 Segue 目的地,我
我有一个 UICollectionView,当用户按下一个单元格时,我会使用 Storyboard在 UINavigationController 中呈现另一个 View Controller 。 -
我是一名优秀的程序员,十分优秀!