需要一點點的幫助,請斯威夫特:插入新CustomTableViewCell行中的TableView
我在我的NavigationController
一個添加按鈕插入一個新CustomTableviewCell
,自定義的tableview單元由一個TextField
的。我已經能夠成功添加新的單元格,但是我無法獲取每個文本字段中的所有文本,並將它們追加到數組中。
var datas: [String] = [""]
static var username = ""
@IBAction func addNewName(_ sender: Any) {
self.isHandlingAddNewUser = true
datas.insert(ViewController.username, at: 0)
tableView.beginUpdates()
tableView.insertRows(at: [IndexPath.init(row: 0, section: 0)], with: .automatic)
tableView.endUpdates()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return datas.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UserCell", for: indexPath) as! UserInputCell
if let name = cell.usernameTextField.text{
ViewController.username = name
}
return cell
}
我缺少什麼,我嘗試打印出datas
,一切都是空的
是什麼'datas.count'? –
我在頂部var datas創建了一個數組:[String] = [「」],我想要做的只是追加數據中的每個文本字段文本 – SimpiMind