Swift Basics

Asked 1 years ago, Updated 1 years ago, 39 views

I'm making something that shows the basic label and slider, but I don't know why the code label.text on Xcode is an error.

error

Swift Compiler Error

Value of type 'UIView' has no member' text'

Did you mean 'next'? (UIKit.UIResponder)

code

import UIKit

classViewController:UIViewController {

   @IBOutlet var label:UIView!
   @ IBAction func showValue(_sender:UISlider){
      label.text="\"(sender.value)"
   }
   override func viewDidLoad(){
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from anib.
   }

   override funcdidReceiveMemoryWarning(){
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
   }

}

swift

2022-09-30 21:27

1 Answers

As you can see in the error message, label is defined as a variable of type UIView and the property UIView does not have the property text, so the compiler type check fails.


2022-09-30 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.