Post

Replies

Boosts

Views

Activity

Xcode | Pickerview & Array question
I am currently using the most updated version of XCODE, and I am trying to implement "pickerview" into my project. How do I asign a string of text to each "tab" of the pickerview, and having each tab assigned a set of data(array). Currently I have my project working without it, where if you press a button it randomly picks a string of text. I am trying to get it so that if you select a tab in the pickerview, it would then use that array when randomly generating, and then the next if you scroll down to another tab. It would then display the randomly generated string to a label. Can anyone help me? I have no idea how to use the pickerview. Im just wondering if I can make my generator more custom from which tab you select in the pickerview class ViewController: UIViewController {   @IBOutlet weak var label: UILabel!   @IBOutlet weak var pickerView: UIPickerView!      override func viewDidLoad() {     super.viewDidLoad()     // Do any additional setup after loading the view.   }   @IBAction func randomWord(_ sender: Any) {           let array = ["I hit it off the toe of the club", "I hit the wrong club", "I haven't played in weeks", "I think im getting old", "******, Fly", "It's this new putter", "Did you see that? This bug just landed on the ball", "Its just too hot to be playing golf" , "I grabbed the wrong club", "Golf is about technique, not playing well" , "I got no sleep last night" , "I haven't played in forever" , "My wife forgot to use the fabric softener again" ,"The group ahead is playing slow, going against my rhythm"]     let array2 = ["Just give up", " Too many excuses", "You're terrible" , "Go Practice"]     counter += 1     if (counter > 9) {       label.text = array2.randomElement()       print(counter)     }     else {       label.text = array.randomElement()       print(counter)     }                           }     }
0
0
461
Jun ’21
Xcode Language Question | Pickerview
I am currently using xcode to design an app. I am trying to implement the "pickerview" into my app. How would I assign text to each picker "tab", and how to assign each tab to a certain array of names. Randomly picking a name depending on what "tab" the pickerview is on when a separate button is clicked. Displaying the generated name to a label (from an array). var counter = 0 class ViewController: UIViewController {   @IBOutlet weak var label: UILabel!   @IBOutlet weak var pickerView: UIPickerView!      override func viewDidLoad() {     super.viewDidLoad()     // Do any additional setup after loading the view.   }   @IBAction func randomWord(_ sender: Any) {           let array = ["I hit it off the toe of the club", "I hit the wrong club", "I haven't played in weeks", "I think im getting old", "Stupid, Fly", "It's this new putter", "Did you see that? This bug just landed on the ball", "Its just too hot to be playing golf" , "I grabbed the wrong club", "Golf is about technique, not playing well" , "I got no sleep last night" , "I haven't played in forever" , "My wife forgot to use the fabric softener again" ,"The group ahead is playing slow, going against my rhythm"]     let array2 = ["Just give up", " Too many excuses", "You're terrible" , "Go Practice"]     counter += 1     if (counter > 9) {       label.text = array2.randomElement()       print(counter)     }     else {       label.text = array.randomElement()       print(counter)     }                           }     }
1
0
640
Jun ’21