以下は私のコードです。私は、背景画像を変更する私のビューに9つのボタンを持っています。私を助けてください。外部メソッドからuibuttonメソッドにアクセスするのがintrestedですが、多くのエラーが発生します
import UIKit
class ViewController: UIViewController {
let alerts = UIAlertController(title: "Hi", message: "Hello", preferredStyle: UIAlertControllerStyle.alert)
let action1 = UIAlertAction(title: "Yes", style: UIAlertActionStyle.default) { (<#UIAlertAction#>) in
for i in 0..<9
{
let newButton = self.view.viewWithTag(i) as! UIButton
newButton.setBackgroundImage(UIImage.init(named: ""), for: .normal)
}
}
@IBAction func buttonPressed(_ sender: UIButton)
{
sender.setBackgroundImage(UIImage.init(named: "cross.png"), for:.normal)
}
}
? – Venkat
エラーは何ですか?どのラインが原因ですか?これらの詳細であなたの質問を編集してください。 – rmaddy
私は蛇口コードのボタンにアクセスしようとしています.. newButton = self.view.viewWithTag(i)を! UIButton newButton.setBackgroundImage(UIImage.init(名前: "")、for:.normal) –