- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 UIStoryboardSegue
类、属性sourceViewController
显然是 UIViewController
.为什么 Apple 将此属性标记为 id
?
@property(nonatomic, readonly) id sourceViewController;
@property(nonatomic, readonly) id destinationViewController;
UIViewController *
会更容易使用或理解吗? , 像
@property(nonatomic, readonly) UIViewController *sourceViewController;
@property(nonatomic, readonly) UIViewController *destinationViewController;
最佳答案
Apple 在这里和许多其他地方使用 id 的原因是允许灵 active 并防止过时。
尽管有属性(property)名称,destinationViewController
可能并不总是返回 UIViewController
目的。或者更具体地说,Apple 不想重构这些方法,如果一年后他们有一些新的、特殊的 View Controller 不继承自 UIViewController
。 .因此,使用 id 可以防止过时。
另请注意,您可能并不总是希望将返回的对象转换为 UIViewController.
例如,如果您的 View Controller 嵌入到 UINavigationController
将由destinationViewController 返回。虽然 UINavigationController
是 UIViewController
的 child ,在大多数情况下,您不想将其转换为这样,因为您通常希望从 viewControllers
中获取其 View Controller 。属性,像这样:
// unwrap the controller if it's embedded in the nav controller.
UIViewController *controller;
if ([segue.destinationViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *navController =
(UINavigationController *)segue.destinationViewController;
controller = [navController.viewControllers objectAtIndex:0];
} else {
controller = segue.destinationViewController;
}
关于ios - 为什么 UIStoryboardSegue 中的 sourceViewController 属性是 "id",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15250642/
我想通过 segue 将我的 View Controller “滑出”到 destinationViewController 上方。这是我的代码: override func perform() {
我目前有两个 View Controller ,我通过 Storyboard segue(导航 Controller )将它们链接起来。当用户在第一个 View 上按下按钮时,屏幕转到第二个 View
在 UIStoryboardSegue类、属性sourceViewController显然是 UIViewController .为什么 Apple 将此属性标记为 id ? @property(no
我是一名优秀的程序员,十分优秀!