我正在尋找一種方法來找到一種更有效的方法來將多個UITextFields(在這種情況下,donorView1,donorView2等)我的報價變化後,只需點擊一個UIButton。點擊Randomize按鈕會產生一個引號數組,但是,使用這個引號數組,我只能得到每個字段一個引號,但是我需要在每個方框中引用不同的引號(即donorView1會有字母DQ,A,DP,DR而donorView2可能有A,C,B,DP)。我對這段代碼很陌生 - 因爲這是我第一次編寫一個iOS應用程序 - 所以如果可能的話,請嘗試用簡單的語言來解釋!每個文本字段至少需要6個隨機字母。如何連續變更多個UITextField中的多個文本值?
@IBOutlet weak var patientView: UITextField!
@IBAction func patientFunction(sender: UIButton!) {
}
@IBOutlet weak var donorView1: UITextField!
@IBOutlet weak var donorView2: UITextField!
@IBOutlet weak var donorView3: UITextField!
@IBOutlet weak var donorView4: UITextField!
@IBOutlet weak var donorView5: UITextField!
@IBOutlet weak var donorView6: UITextField!
@IBOutlet weak var donorView7: UITextField!
@IBOutlet weak var donorView8: UITextField!
@IBOutlet weak var Randomize: UIButton!
@IBAction func Randomize(sender: UIButton!) {
let quoteArray1 = [" -A,", " -B,", " -C,", " -DR,", " -DQ, ", " -DP,"]
self.patientView.text = quoteArray1 [Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView1.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView1.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView2.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView3.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView4.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView5.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView6.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView7.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
self.donorView8.text = quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))] + quoteArray1[Int(arc4random_uniform(UInt32(quoteArray1.count)))]
}
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.
}
你爲什麼不使用'IBOutletCollection'代替'IBOutlet'? –