【发布时间】:2016-05-10 13:40:18
【问题描述】:
我正在尝试制作一个应用程序,用户可以在其中添加一个单元格,并且他可以在其中向单元格添加不同的内容,例如姓名、生日和爱好。 到现在为止还挺好。 但是我怎样才能向他展示每个单元格的各个内容? 我是否必须添加具有不同标签的 ViewController,在其中加载为特定单元格保存的文本,例如使用 NSuserdefaults/Coredata? 还是我完全错了?
我现在拥有的:在我的 viewController 中我可以添加一个项目
@IBAction func doneButtonPressed(sender: AnyObject) {
name = txtFieldName.text!
vc.items.append(name)
vc.tableView.reloadData()
self.dismissViewControllerAnimated(false, completion:nil)
}
在我的 tableviewController 中:
var items = [String]();
override func viewDidLoad() {
super.viewDidLoad()
print(items)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("itemCell", forIndexPath: indexPath)
cell.textLabel!.text = items[indexPath.row]
return cell
}
【问题讨论】:
-
请提供一些示例代码以使这个问题更清楚。
-
现在如何在创建每个单元格时保存每个单元格的数据以及如何为每个单元格加载不同的内容。
标签: swift uitableview core-data cell nsuserdefaults