从segue swift填充动态数组

时间:2015-08-19 19:52:11

标签: arrays swift segue

第一个视图我准备删除3个textFields :(抱歉我的英文不好)

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if (segue.identifier == "salvar") {
        var view = segue.destinationViewController as! SecondView
        view.end = endereco.text
        view.area = area.text
        view.data = data.text 
    }
}

问题出在第二个视图上,数组正在重复(并且不要将新数据添加到数组中,只能替换它),使得3个标签从单元格重复使用相同的数据,继承第二个View代码:

class secondView: UITableViewController {

var end = ""
var area = ""
var data = ""

var array: [String] = []

override func viewDidLoad() {
    super.viewDidLoad()

    self.array = [end, area, data]
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return self.array.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! AgendaCell

    cell.label1.text = self.array[indexPath.row] as String
    cell.label2.text = self.array[indexPath.row] as String               
    cell.label3.text = self.array[indexPath.row] as String

    return cell
}

我怎样才能真正地将新数据添加到数组中,并将每个数据放入单元格中的有序标签?

0 个答案:

没有答案