需要帮助将多个字符串从一个 .XIB 文件传输到视图控制器
Need help transferring multiple strings from one .XIB file to a view controller
我的目标是尝试将多个名称从 XIB 视图中的一个输入传递到视图控制器文件。很简单的问题,网上没找到解决方法
这就是我目前用来尝试传输字符串输入的内容。
let nameOne = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameOne.swimmerOneName = swimmerOneTextField.text!
let nameTwo = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameTwo.swimmerTwoName = swimmerTwoTextField.text!
let nameThree = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameThree.swimmerThreeName = swimmerThreeTextField.text!
let nameFour = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameFour.swimmerFourName = swimmerFourTextField.text!
navigationController?.pushViewController(nameOne, animated: true)
navigationController?.pushViewController(nameTwo, animated: true)
navigationController?.pushViewController(nameThree, animated: true)
navigationController?.pushViewController(nameFour, animated: true)
我的问题是它每次也只传送一个名字和一个动画。我已经尝试将 "animated: true" 设置为 false,但它仍然一次只传输一个名字。
为了更清楚地说明这就是我要完成的工作。这是使用 segues 和故事板完成的,而不是 XIB:图片 1 和 2
这就是我想要转移所有名称时发生的事情:图像 3 和 4。它循环遍历每个名称,而不是像图像 2 那样一次保留所有名称。
您可以定义一个字符串的全局数组并使用该数组传输您的文本,但更好的方法是使用其中一种传递数据的方法。
我的目标是尝试将多个名称从 XIB 视图中的一个输入传递到视图控制器文件。很简单的问题,网上没找到解决方法
这就是我目前用来尝试传输字符串输入的内容。
let nameOne = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameOne.swimmerOneName = swimmerOneTextField.text!
let nameTwo = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameTwo.swimmerTwoName = swimmerTwoTextField.text!
let nameThree = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameThree.swimmerThreeName = swimmerThreeTextField.text!
let nameFour = TwoMedleyStopwatch(nibName: "TwoMedleyStopwatch", bundle: nil)
nameFour.swimmerFourName = swimmerFourTextField.text!
navigationController?.pushViewController(nameOne, animated: true)
navigationController?.pushViewController(nameTwo, animated: true)
navigationController?.pushViewController(nameThree, animated: true)
navigationController?.pushViewController(nameFour, animated: true)
我的问题是它每次也只传送一个名字和一个动画。我已经尝试将 "animated: true" 设置为 false,但它仍然一次只传输一个名字。
为了更清楚地说明这就是我要完成的工作。这是使用 segues 和故事板完成的,而不是 XIB:图片 1 和 2
这就是我想要转移所有名称时发生的事情:图像 3 和 4。它循环遍历每个名称,而不是像图像 2 那样一次保留所有名称。
您可以定义一个字符串的全局数组并使用该数组传输您的文本,但更好的方法是使用其中一种传递数据的方法。