我正在寻找一种方法来找到一种更有效的方法来将多个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'? –