我有一个自定义分段控件,它将不同的字符串传递到一个单独的类中的函数中,然后将该文本设置为UITextField& UITextView的。我不明白的是我可以从分段控件中进行不同的选择并打印出正确的值,但是当我尝试将值设置为TextField和TextView时,我得到“在展开可选值时意外发现nil”。任何帮助将不胜感激。
//FirstViewController
override func viewDidLoad() {
super.viewDidLoad()
NameOfPost.text = "Name Your SKill"
DescriptionOfPost.text = "Enter Skill Description"
}
func setDescriptionText(setSelectedText: String){
print("\(setSelectedText)")
DescriptionOfPost.text = setSelectedText
}
func setNameText(setSelectedText: String){
print("\(setSelectedText)")
NameOfPost.text = setSelectedText
}
//@IBDesignable class HBSegmentedControl
func displayNewSelectedIndex(){
let setSkillDescriptionText = "Skill Description text"
let setTipDescriptionText = "Tip Description text"
let setStoryDescriptionText = "Story Description text"
let setSkillNameText = "Name Your Skill"
let setTipNameText = "Name Your Tip"
let setStoryNameText = "Name Your Story"
let storyboard: UIStoryboard =
UIStoryboard.init(name: "Main",bundle: nil);
let firstViewController:
ComposeViewController = storyboard.instantiateViewController(withIdentifier: "ComposeViewController") as! ComposeViewController;
//call setDescriptionText & setNameText from the first view controller and pass in the selected name & description
if selectedOption == 0 {
print("Skill")
firstViewController.setDescriptionText(setSelectedText: setSkillDescriptionText)
firstViewController.setNameText(setSelectedText: setSkillNameText)
}else if selectedOption == 1{
print("Tip")
firstViewController.setDescriptionText(setSelectedText: setTipDescriptionText)
firstViewController.setNameText(setSelectedText: setTipNameText)
}else if selectedOption == 2{
print("Famous-Faces")
firstViewController.setDescriptionText(setSelectedText: setStoryDescriptionText)
firstViewController.setNameText(setSelectedText: setStoryNameText)
}
}