Я хочу передать данные через текстовое поле и в массив (Second View Controller), чтобы его можно было добавить в пул данных и выбрать случайным образом.
Например, вы должны ввести свое имя (и / или другое имя) в текстовое поле в первом виртуальном виртуальном канале, и оно будет помещено в массив, который скажет им, какого цвета они отображаются во втором виртуальном канале.
По сути, я пытаюсь передать данные в переменную (которая будет содержать все введенные имена), добавить переменную в массив, затем нажать кнопку, чтобы сгенерировать и случайным образом извлечь из массива с помощью arc4random. Моя проблема - это не добавление. Любая помощь будет принята с благодарностью.
Вот мой код:
VC 1:
import UIKit
class ViewController: UIViewController {
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.
}
@IBAction func StartTapped(_ sender: Any) {
performSegue(withIdentifier: "SecondViewControllerSegue", sender: self)
}
@IBOutlet weak var AddPlayerTextField: UITextField!
@IBAction func AddTexttoArrayBtn(_ sender: Any) {
if AddPlayerTextField.text == nil
{
performSegue(withIdentifier: "SecondViewControllerSegue", sender: self)
}
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let SecondViewController = segue.destination as! ViewController2
SecondViewController.myString = AddPlayerTextField.text!
VC 2:
import UIKit
class ViewController2: UIViewController {
var myString = String ()
var TeamBuildingQuestions = [ "is Red", "is Blue", "is Green", "is Purple","is Teal","is Orange", "is Red", "is Grey", "is Pink"]
var MasterTeamBuildingQuestionsArray = [ "Hello", "beep bop bbeep", "Boop", "Bap","Bospop","bob the builder"]
@IBOutlet weak var DisplayArray: UILabel!
@IBAction func NextQuestionBtn(_ sender: Any) {
let RandomArrayNumber = Int (arc4random_uniform(UInt32(TeamBuildingQuestions.count)))
let QuestionDisplayed = TeamBuildingQuestions[RandomArrayNumber]
DisplayArray?.text = QuestionDisplayed
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
TeamBuildingQuestions.append(myString)
}