所以我想通過按鈕「移動到新的tableview」(檢查圖片)將我的tableview從「ViewController」轉移到我的「SecondViewController」。 而在我的桌面視圖中,我想讓所有的單元格都添加在那裏pelaajat.append如何將tableview移動到新的tableview與按鈕之外tableview
模擬器和故事板圖像在下面給出。
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var tableView: UITableView!
var pelaajat = [String]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView(frame: CGRect.zero)
}
@IBAction func movetoNewTableview(_ sender: Any) {
}
@IBAction func addName(_ sender: Any) {
lisaaPelaajanNimi()
}
func lisaaPelaajanNimi(){
pelaajat.append(textField.text!)
let indexPath = IndexPath(row: pelaajat.count - 1, section: 0)
tableView.beginUpdates()
tableView.insertRows(at: [indexPath], with: .automatic)
tableView.endUpdates()
textField.text = ""
view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return pelaajat.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
cell.textLabel?.text = pelaajat[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete{
pelaajat.remove(at: indexPath.row)
tableView.beginUpdates()
tableView.deleteRows(at: [indexPath], with: .automatic)
tableView.endUpdates()
}
}
}
你想要的是將細胞(數據)移動到另一個UIViewController內的另一個tableview? –
你和其他UIViewController裏面的tableview也 – Tonil92
傳遞數據並顯示在第二個視圖控制器在tableView ...爲什麼移動單元格??當你可以傳遞數據......給一些更多的細節你試圖用這個來達到什麼所以我可以幫你 –