细分名称是Entrada.我这样做:
override func viewDidLoad() { super.viewDidLoad() Entrada(sender: UISegmentedControl) { setTitle("Action 1", forSegmentAtIndex: 0) setTitle("Action 2", forSegmentAtIndex: 1) setTitle("Action 3", forSegmentAtIndex: 2) }
我得到错误......哇.
Swift 3.0使用:
@IBOutlet weak var entrada : UISegmentedControl! override func viewDidLoad() { super.viewDidLoad() entrada.setTitle("Action 1", forSegmentAt: 0) entrada.setTitle("Action 2", forSegmentAt: 1) entrada.setTitle("Action 3", forSegmentAt: 2) }
您必须将分段控件连接到IBOutlet
Interface Builder中,然后才能编写
@IBOutlet var entrada : UISegmentedControl! override func viewDidLoad() { super.viewDidLoad() entrada.setTitle("Action 1", forSegmentAtIndex: 0) entrada.setTitle("Action 2", forSegmentAtIndex: 1) entrada.setTitle("Action 3", forSegmentAtIndex: 2) }
在Swift 3+中,语法已更改为
override func viewDidLoad() { super.viewDidLoad() entrada.setTitle("Action 1", forSegmentAt: 0) entrada.setTitle("Action 2", forSegmentAt: 1) entrada.setTitle("Action 3", forSegmentAt: 2) }