从一个IBAction到另一个Swift的浮点数

时间:2018-07-29 05:59:27

标签: swift

我到处搜索,似乎找不到任何答案。我是在Xcode上使用Swift的新手,在使用Objective-C之前。在Objective-C上,我可以在一个IBAction中获取一个数字,并将其作为浮点数,然后在另一个IBAction中再次使用它。

喜欢

Float number

-(IBAction)winch
{
  number=1;
}
-(IBAction)fuel
{
  number=2;
}  
-(IBAction)tire
{
  number=3;
}
-(IBAction)tow
{
  number=4;
}
-(IBAction)jump
{
  number=5;
}
-(IBAction)battery
{
  number=6;
}
-(IBAction)unlock
{
  number=7;
}
-(IBAction)show
{
  numberField.text=(@"@f",number)
{

在Swift中有什么方法可以做同样的事情吗?

1 个答案:

答案 0 :(得分:0)

var number = 0

@IBAction func winch (_ sender:Any) {
    number = 1
}

@IBAction func fuel (_ sender:Any) {
    number = 2
}

@IBAction func tire (_ sender:Any) {
    number = 3
}   

@IBAction func tow (_ sender:Any) {
    number = 4
}

@IBAction func jump (_ sender:Any) {
    number = 5
}

@IBAction func battery (_ sender:Any) {
    number = 6
}

@IBAction func unlock (_ sender:Any) {
    number = 7
}

func show () {
    numberField.text = "\(number)"
}