xcode internalContentSize() - 方法不会覆盖其超类中的任何方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38881151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:07:56  来源:igfitidea点击:

intrinsicContentSize() - Method does not override any method from its superclass

swiftxcodeuiview

提问by GoldenJoe

I updated to Xcode 8 beta 5, and now get the following error on a class that inherits from UIView:

我更新到 Xcode 8 beta 5,现在在继承自 UIView 的类上出现以下错误:

Method does not override any method from its superclass

override public func intrinsicContentSize() -> CGSize
{
   ...
}

Is there a workaround?

有解决方法吗?

回答by OOPer

Please check the latest reference. (You can easily find it just putting the word "intrinsicContentSize" in the searchbar of Apple's developer site.)

请查看最新的参考资料。(您只需在Apple 开发者网站的搜索栏中输入“intrinsicContentSize”一词即可轻松找到它。)

Declaration

var intrinsicContentSize: CGSize { get }

宣言

var intrinsicContentSize: CGSize { get }

intrinsicContentSizehas become a computed property, so you need to override it in this way:

intrinsicContentSize已成为计算属性,因此您需要以这种方式覆盖它:

override open var intrinsicContentSize: CGSize {
    get {
        //...
        return someCGSize
    }
}

Or simply:

或者干脆:

override open var intrinsicContentSize: CGSize {
    //...
    return someCGSize
}

回答by Imanou Petit

While transitioning from one version of Xcode to another, there is different ways to find out why your code does not compile anymore. Here are a few resources for intrinsicContentSize:

从一个 Xcode 版本转换到另一个版本时,有多种方法可以找出您的代码不再编译的原因。以下是一些资源intrinsicContentSize

  1. You can search for intrinsicContentSizefrom developer.apple.com.
  2. You can search for intrinsicContentSizestraight from Apple Developer API Reference page for UIView.
  3. You can open the iOS 10.0 API Diffs for UIKit pageand search for instances of intrinsicContentSizewith your browser's find menu(shortcut: cmd+ F).
  4. You can search for intrinsicContentSizefrom Xcode's Documentation and API Reference(path: Help> Documentation and API Reference, shortcut: shift+ cmd+ 0).
  5. You can also right-click on any UIViewinitializer in your Xcode code (for example, UIView()), select Jump to Definitionand then perform a search for intrinsicContentSize.
  1. 您可以intrinsicContentSizedeveloper.apple.com搜索。
  2. 您可以intrinsicContentSize直接从Apple Developer API Reference 页面搜索 UIView
  3. 您可以打开iOS 10.0 API Diffs for UIKit 页面intrinsicContentSize使用浏览器的查找菜单(快捷键:cmd+ F)搜索实例。
  4. 您可以搜索intrinsicContentSize从Xcode的文档和API参考(路径:Help> Documentation and API Reference,便道:shift+ cmd+ 0)。
  5. 您还可以右键单击UIViewXcode 代码中的任何初始值设定项(例如,UIView()),选择Jump to Definition并搜索intrinsicContentSize.


These searches will show you that intrinsicContentSize, with Swift 3 and iOS 10, is no more a method but a computed property of UIViewthat has the following declaration:

这些搜索将告诉您intrinsicContentSize,在 Swift 3 和 iOS 10 中, 不再是方法,而是UIView具有以下声明的计算属性:

var intrinsicContentSize: CGSize { get }

var intrinsicContentSize: CGSize { get }



As a consequence, you will have to replace your intrinsicContentSize()method implementation with the following code snippet:

因此,您必须intrinsicContentSize()使用以下代码片段替换您的方法实现:

override public var intrinsicContentSize: CGSize {
    return ...
}