UITextView 的指定初始化器 [英] Designated Initializer of UITextView

查看:37
本文介绍了UITextView 的指定初始化器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Xcode 6 Beta 中创建 UITextView 的新子类时,会自动提供以下代码.

When I create a new subclass of UITextView in the Xcode 6 Beta, the following code is automatically provided.

import UIKit

class TerminalView: UITextView {

    init(frame: CGRect) {
        super.init(frame: frame)
        // Initialization code
    }
}

之前的代码(完全由 Xcode 提供,没有删除任何内容)给出了以下错误.

The previous code (completely provided by Xcode with nothing removed) gives the following error.

必须调用超类'UITextView'的指定初始化器

据我所知,为 UIView 的所有子类指定的是 -initWithFrame:(或者在 Swift 中,init(frame:)>. 如果是这种情况,为什么 Xcode 提供的代码会导致错误? 我没有向类添加新的实例变量,所以还没有其他任何东西需要初始化.

As far as I know, the designated for all subclasses of UIView is -initWithFrame: (or in Swift, init(frame:). If this is the case, why does the code provided by Xcode result in an error? I have added no new instance variables to the class, so nothing else has to be initialized yet.

推荐答案

似乎现在唯一有效的初始化程序是:

It seems as though the only initializer that works for now is:

super.init(frame: CGRect, textContainer: NSTextContainer?)

可以用

super.init(frame: CGRect.zero, textContainer: nil)

这很可能是初始 Beta 版中的一个错误,将在即将发布的 Beta 版中修复.

This is most likely a bug in the initial beta release and will be fixed in upcoming beta releases.

这篇关于UITextView 的指定初始化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆