【发布时间】:2014-12-15 19:24:37
【问题描述】:
我正在写一个笔记应用程序,仅供参考。我设置了数组,并使用以下代码提供了一个表格:
import UIKit
import Foundation
var tableData = ["Pancake Recipe", "Costume Party", "Camping Supplies"]
var tableSubtitle = ["Some Milk and some Flour", "Let's dress up like Jen", "Tenting with Lucy"]
class ViewController: UIViewController {
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return tableData.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier:"cell")
cell.textLabel!.text = tableData.reverse()[indexPath.row]
cell.detailTextLabel!.text = tableSubtitle.reverse()[indexPath.row]
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
var listTitle = "Notes"
self.title = listTitle
UIApplication.sharedApplication().statusBarStyle = .LightContent
}
override func viewDidAppear(animated: Bool) {
println(tableSubtitle)
}
}
用户为不同页面上的单元格创建新标题和副标题,并将它们添加到数组(tableData 和 tableSubtitle 数组)中。我知道数据的添加工作正常,因为当我观看控制台时,它完美地打印了两个更新的数组。
然后当我返回主视图控制器时,我看到了一个额外的单元格(如我所愿),但不是我想要的新内容,而是“煎饼食谱”单元格的副本。
再次加载视图时是否需要刷新单元格的内容?如果是这样,我该怎么做?
谢谢:)
作为参考,这是两次向两个数组添加数据后的表格视图图片,然后我返回到表格视图,尽管两个数组现在都包含两个额外且不同的条目(已检查使用 println(tableData) 和 println(tableSubtitle)
【问题讨论】:
-
你能添加你用来添加新单元格的代码吗?那么或许可以为你提供更有用的答案