问题 当我进入视图控件时,如何更改3段控制段的标题?


细分名称是Entrada。 我这样做:

override func viewDidLoad() {
    super.viewDidLoad()

    Entrada(sender: UISegmentedControl) {
        setTitle("Action 1", forSegmentAtIndex: 0)
        setTitle("Action 2", forSegmentAtIndex: 1)
        setTitle("Action 3", forSegmentAtIndex: 2)
    }

我得到错误......哇。


13037
2017-12-24 15:07


起源



答案:


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) 
 } 

8
2018-03-04 00:37





您必须将分段控件连接到 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) 
} 

6
2017-12-24 15:13



我在下面这样做了:@IBAction func Entrada(发件人:UISegmentedControl){code}但没有成功:(我得到一条消息说Entrada没有setTitle成员 - fr0zt
这是一 IBAction 当分割控件被轻敲时调用,a IBOutlet 是对Interface Builder中UI元素的引用。解释您需要的问题的标题 IBOutlet - vadian
做了但现在它崩溃了...... :( - fr0zt
你也连接了 IBOutlet 在Interface Builder中通过控制拖动到类对象(声明行左边的小圆圈必须是暗的)? - vadian
你能解释一下怎么做吗?我一直在寻找它,但没有成功 - fr0zt


答案:


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) 
 } 

8
2018-03-04 00:37





您必须将分段控件连接到 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) 
} 

6
2017-12-24 15:13



我在下面这样做了:@IBAction func Entrada(发件人:UISegmentedControl){code}但没有成功:(我得到一条消息说Entrada没有setTitle成员 - fr0zt
这是一 IBAction 当分割控件被轻敲时调用,a IBOutlet 是对Interface Builder中UI元素的引用。解释您需要的问题的标题 IBOutlet - vadian
做了但现在它崩溃了...... :( - fr0zt
你也连接了 IBOutlet 在Interface Builder中通过控制拖动到类对象(声明行左边的小圆圈必须是暗的)? - vadian
你能解释一下怎么做吗?我一直在寻找它,但没有成功 - fr0zt