私の質問は、特に以下の一連のアクションに関連しています。ユーザーがtextFieldにテキストを入力し、ボタンを押してからテキストを入力できるようにしたいセルに転送された後、テーブルに新たに移入されます。TextFieldテキストを含むセルを追加するボタンXcode/Swift 2.0
私は、テキストフィールド、ボタン、およびテーブルオブジェクトを持つビューコントローラを1つ持っています。
UPDATE 1: "self.taskTable.delegate = self"と "self.taskTable.dataSource = self"が追加されました。これは、ユーザーがテキストを入力するときに各文字列を格納する配列を持っています。コメントに示唆されているように。
更新2:ストーリーボードエディタで識別子を追加するのを忘れました。コードは機能しています、ありがとう皆さん!次のようにコードがある:あなたのviewDidLoad()
にデリゲートの参照を追加しなかった
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var textField: UITextField!
@IBOutlet var taskTable: UITableView!
var taskArray : NSMutableArray! = NSMutableArray() //Could be a non-NS as well
@IBAction func addTask(sender: AnyObject) {
//Print to alert we entered method
print("task submitted")
//Get input from text field
let input = textField.text
//Add object to array, reload table
self.taskArray.addObject(input!)
self.taskTable.reloadData()
}//addTask
override func viewDidLoad() {
super.viewDidLoad()
self.taskTable.delegate = self
self.taskTable.dataSource = self
print("application finished loading")
// 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 numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.taskArray.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = self.taskTable.dequeueReusableCellWithIdentifier("cell")!
cell.textLabel?.text = self.taskArray.objectAtIndex(indexPath.row) as? String
return cell
}
}
あなたの質問は何ですか? – Emptyless
私が現在提示しているコードはうまくいきませんので、機能が得られるように変更が加えられたのかどうか疑問に思っています – jb990