无法调用非函数类型的值"任何对象!?"迅速



>我正在尝试修复此错误,但没有看到解决方案。在其他代码中有效!没有意义!

支持类滚动字符串:在滚动的视图中打印字符串。

class ScrolledString: NSView{
var text: NSString = "";
init(frame frameRect: NSRect, string:NSString){
    self.text = string
    super.init(frame: frameRect)
}
required init?(coder: NSCoder) {
    self.text = ""
    super.init(coder:coder)
}
override func drawRect(dirtyRect: NSRect) {
    let font = NSFont(name: "Helvetica", size: 40.0)
    let attrs : [String: AnyObject] = [
        NSFontAttributeName: font!,
        NSForegroundColorAttributeName: NSColor.whiteColor()
    ]
    text.drawInRect(self.frame, withAttributes: attrs)
}

比在主视图中,我正在尝试添加滚动视图

let scrollStringContainer = NSScrollView(frame: NSRect(x: myRect.width*4/9, y: 0, width: myRect.width*8/9, height: myRect.height))
let view = NSView()
view.addSubview(ScrolledString(frame: scrollStringContainer.frame, string: self.name))
scrollStringContainer.documentView(view)

最后一行返回错误"无法调用 nun-function 类型'AnyObject'的值"。我只是想添加一个视图来滚动视图

unowned(unsafe) var documentView: AnyObject?

documentViewAnyObject 类型的可选属性,因此不能像函数一样调用它。我不清楚你的意思是使用contentView,如:

scrollStringContainer.contentView.addSubview(view)

相关内容

最新更新