我的第一個View Controller有一個TableView。需要幫助將數據添加到TableView
在第二個視圖控制器上,用戶將輸入數據並單擊一個按鈕。
我想要這個按鈕添加數據到表視圖,但我無法弄清楚如何做到這一點。
var textArray: NSMutableArray! = NSMutableArray()
@IBOutlet weak var tableView: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.textArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return UITableViewCell()
}
@IBOutlet weak var addData: UIButton!
@IBAction func addData(sender: AnyObject) {
self.textArray.addObject(textField.text)
self.tableView.reloadData()
}
這也帶來了一個錯誤我reloadData
行代碼。
這可能會有幫助...在Objective-C中的答案,但原則保持不變。 http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers或http://stackoverflow.com/questions/25540141/how-can-i-pass-information-from-one-view-控制器到另一個 – Mike