Reputation: 13
I'm trying to make it so when I click a tableviewcell in my tableviewcontroller it segues to another viewcontroller and uses the text that was in the cell and automatically fills the uitextfield in the controller that it was segued too.
I was thinking it would start from this method
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
Clicked in this controller and uses the text in the cell
Add Exercise TableView Controller
Fills the exercise uitextfield with text
In Swift btw. Thanks.
Upvotes: 0
Views: 60
Reputation: 207
- 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
}
}
Upvotes: 1