相关疑难解决方法(0)

如何参考Swift Playground本身?

如何以编程方式创建按钮?

自我在快速游乐场不起作用:

button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
Run Code Online (Sandbox Code Playgroud)

错误:

游乐场执行失败:错误:: 42:13:错误:使用未解析的标识符'self'

我也尝试用里面的buttonAction方法创建一个类,但是当我点击按钮时,没有任何东西在控制台中打印

import UIKit

class myself {


    func buttonAction(sender:UIButton!)
    {
        println("Button tapped")
    }

}

var s = myself()

// Create View
var f = CGRect(x:0,y:0,width:200,height:200)
var view = UIView(frame:f)


// Create Button
var b = UIButton(frame: f)
b.setTitle("Hello", forState: UIControlState.Normal)
b.addTarget(s, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)

view.addSubview(b)

view
Run Code Online (Sandbox Code Playgroud)

swift swift-playground

10
推荐指数
2
解决办法
5412
查看次数

标签 统计

swift ×1

swift-playground ×1