0
これは私のプログラムです。初心者ですが、ビルドは成功しましたが、実行中止です。ビルドが成功し私はこのプログラムスタックに入っているか、動作しなくなります
import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var items = [String]()
@IBOutlet var textField: UITextField!
@IBOutlet weak var tableView: UITableView!
@IBAction func addButton(sender: UIButton) {
let newItem = textField.text
items.append(newItem!)
textField.resignFirstResponder()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:
NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell",forIndexPath: indexPath)
cell.textLabel?.text = items[indexPath.row]
cell.textLabel?.textColor = UIColor.redColor()
return cell
}
}
、私は0かnil を示すフロー上のスタックでエラーが出るランニングであなたは助けることはできますか?
ようなあなたのIBActionでそれを追加し、あなたの
datasource
しようとする
newItem
を追加した後tableView.reloadData()
が欠けていると思います – Israel