import UIKit
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
let players = ["Player A", "Player B", "Player C", "Player D", "Player E"] // Replace with actual player names
let places = ["First Place", "Second Place", "Third Place"]
@IBOutlet weak var firstPlacePicker: UIPickerView!
@IBOutlet weak var secondPlacePicker: UIPickerView!
@IBOutlet weak var thirdPlacePicker: UIPickerView!
override func viewDidLoad() {
super.viewDidLoad()
firstPlacePicker.dataSource = self
firstPlacePicker.delegate = self
secondPlacePicker.dataSource = self
secondPlacePicker.delegate = self
thirdPlacePicker.dataSource = self
thirdPlacePicker.delegate = self
}
@IBAction func submitVotes(_ sender: UIButton) {
let firstPlacePlayer = players[firstPlacePicker.selectedRow(inComponent: 0)]
let secondPlacePlayer = players[secondPlacePicker.selectedRow(inComponent: 0)]
let thirdPlacePlayer = players[thirdPlacePicker.selectedRow(inComponent: 0)]
print("First Place: \(firstPlacePlayer)")
print("Second Place: \(secondPlacePlayer)")
print("Third Place: \(thirdPlacePlayer)")
// Optionally, show an alert or message confirming the submission
let alert = UIAlertController(title: "Votes Submitted", message: "Thank you for your votes!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(alert, animated: true, completion: nil)
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return players.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return players[row]
}
}