我试图做到这一点,以便当我单击 tableviewcontroller 中的 tableviewcell 时,它会转至另一个 viewcontroller 并使用单元格中的文本,并自动填充 Controller 中的 uitextfield ,它也被转接了。
我想从这个方法开始
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
单击此 Controller 并使用单元格中的文本
Add Exercise TableView Controller
用文本填充练习 uitextfield
顺便说一句,在 Swift 中。谢谢。
最佳答案
- Create a Segue in the storyboard and give it an identifier("YourSegue")
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let text = "Your text"
performSegueWithIdentifier("YourSegue", sender: text)
}
- Then Call This function
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "YourSegue" {
let yourOtherVC = segue.destinationViewController as? YourOtherViewController
if let text = sender as? String {
yourOtherViewController?.text = text
}
}
}
- Put this variable in the ViewController that you want to show(YourOtherViewController).
var text: String
override func viewDidLoad() {
super.viewDidLoad()
if text != nil {
yourTextField.text = text
}
}
关于swift - 当 uitableviewcell 被点击时,序列到 viewcontroller 并用所选单元格中的文本快速填充 uitextfield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37232390/