-3

基本のラベルとsliderを表示するものを作っているんですが、Xcode上でlabel.textのコードがなぜエラーになるのかわかりません。

エラー

Swift Compiler Error

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

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

コード

import UIKit

class ViewController: 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 a nib.
   }

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

}
1
  • ツアーをご覧ください。プログラミングに関する質問は、画像でなく質問中にあなた自身の言葉で説明された方がよいでしょう。
    – yohjp
    2017年10月7日 6:46

1 件の回答 1

1

エラーメッセージの通りです。labelUIView型の変数として定義されていて、UIViewにはtextというプロパティは無いので、存在しないプロパティに値を代入しようとしているため、コンパイラの型チェックでエラーになっています。

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。