swift - 当 uitableviewcell 被点击时,序列到 viewcontroller 并用所选单元格中的文本快速填充 uitextfield

标签 swift uitableview uitextfield segue

我试图做到这一点,以便当我单击 tableviewcontroller 中的 tableviewcell 时,它会转至另一个 viewcontroller 并使用单元格中的文本,并自动填充 Controller 中的 uitextfield ,它也被转接了。

我想从这个方法开始

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {



}

Exercise TableView Controller

单击此 Controller 并使用单元格中的文本

Add Exercise TableView Controller

用文本填充练习 uitextfield

顺便说一句,在 Swift 中。谢谢。

最佳答案

  1. 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)
}
  1. 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    
       }  
     } 
    }
  1. 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/

相关文章:

IOS swift 3 : Flip Front Camera Image Horizontally after taking Camera Picture

ios - 使用 xib 和自动布局的自定义 UITableViewCell 无法在顶部的多个单元格中正确显示

iOS 图表编译错误

ios - 带有 leftViewMode 的 UITextField UITextFieldViewModeUnlessEditing 在编辑时保持可见

ios - iOS 版 Simperium 中的 API key

ios - UITableViewCell 标签不需要的缩进

ios - 我正在尝试缩进表格 View 单元格文本标签的右边距

ios - 我无法从自定义 UITableViewCell 中删除自定义 UIButton

iOS:更改 StackView 中 TextField 的高度(在 StackView 内)

ios - 插入多个字符时关闭文本字段