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或零 你能幫得到錯誤?
添加reloaData後缺少
tableView.reloadData()
沒有幫助我 – Israel