-1
這是代碼:如何將字符串保存到表格視圖?
import UIKit
var reminder = [String]()
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var textField: UITextField!
@IBAction func checkMarkTapped(sender: AnyObject) {
reminder.append(textField.text!)
textField.text = ""
}
@IBAction func addReminder(sender: AnyObject) {
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return reminder.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:CoustemCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CoustemCell
cell.tableViewLabel.text = reminder[indexPath.row]
return cell
}
}
所以我當過你按checkMarkTapped它將添加任何被放置在文本框的表視圖。但是我放入checkMarkTapped的代碼假設可以正常工作,但會一直崩潰。
那麼我做錯了什麼?
它在崩潰時說什麼? – EmilioPelaez
您是否已將文本字段分配給文本字段插座? – Paulw11