0
我想用表格視圖中的原型單元格填充用戶輸入到先前視圖控制器中的文本字段中的信息。我想使用這個數據來設置每個單元格的標題和副標題,而不是預先確定的數組。如何將數據從視圖控制器中的文本字段傳遞到表格單元視圖的標題/副標題部分?使用以前視圖中的文本字段中的數據填充表格視圖單元格
任何幫助表示讚賞。
我想用表格視圖中的原型單元格填充用戶輸入到先前視圖控制器中的文本字段中的信息。我想使用這個數據來設置每個單元格的標題和副標題,而不是預先確定的數組。如何將數據從視圖控制器中的文本字段傳遞到表格單元視圖的標題/副標題部分?使用以前視圖中的文本字段中的數據填充表格視圖單元格
任何幫助表示讚賞。
首先在要原因請看你TableViewController點實現這個:
let textFieldString = yourTextField.text ?? ""
performSegueWithIdentifier("exampleID", sender: textFieldString)
在你的故事板現在創建正確的SEGUE!在執行之前賽格瑞
1)From the whole ViewController to your destination ViewController
2)And don't forget your unique segue-ID
委託方法prepareForSegue(...)將被調用。在這種方法中,您準備好您的目標ViewController。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
let targetvc = segue.destinationViewController as? YourTableViewController
if let targetvc = targetvc
{
let yourTextFieldString = sender as? String
if let yourTextFieldString = yourTextFieldString
{
targetvc.yourTextFieldString = yourTextFieldString
}
}
}
當執行SEGUE到目的地的ViewController,你的變量(這裏在這種情況下,「yourTextFieldString」)的前一組數據。
class yourTableViewController : UITableViewController
{
var yourTextFieldString = "" // This variable has the previous set data
override func viewDidLoad()
{
super.viewDidLoad()
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("yourCellID", forIndexPath: indexPath)
cell.textLabel.text = yourTextFieldString
return cell
}
}
現在調整你的原型單元格(不要忘記正確的標識符),你就完成了。
你的問題很廣泛,你想知道如何在控制器之間傳遞數據嗎?或者如何填充UITableViewCell?爲了獲得答案,你需要更新你的問題,以顯示你迄今爲止做了什麼,使用的代碼等。這將使人們能夠準確地幫助 –