无法显示自定义viewcontroller里新增的数据?
这是主界面viewcontroller显示cell的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
print("\(todo.count)")
let cell = self.tableview.dequeueReusableCellWithIdentifier("todocell")! as UITableViewCell
let todos = todo[indexPath.row] as Todo
let images = cell.viewWithTag(1) as! UIImageView
let title = cell.viewWithTag(2) as! UILabel
let date = cell.viewWithTag(3) as! UILabel
images.image = UIImage(named: todos.image)
title.text = todos.title
date.text = returnDateformatter().stringFromDate(todos.date)
return cell
}
//MARK -
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){
if editingStyle == UITableViewCellEditingStyle.Delete{
todo.removeAtIndex(indexPath.row)
self.tableview.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
viewdidiload里面的:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
todo.append(Todo(id: "1", image:"child-selected", date: datefromstring("2015-12-12")!, title: "1. 带弟弟去游乐场"))
todo.append(Todo(id: "3", image:"shopping-cart-selected", date: datefromstring("2015-12-15")!, title: "3. 去商场买东西"))
todo.append(Todo(id: "1", image:"travel-selected", date: datefromstring("2016-1-1")!, title: "4. 旅行计划"))
todo.append(Todo(id: "ss", image: "child-selected", date: datefromstring("2011-11-11")!, title: "fuck"))
navigationItem.leftBarButtonItem = editButtonItem()
}
自定义viewcontroller力oktyped按钮的方法:
@IBAction func addTyped(sender: AnyObject) {
var image = ""
if childbutton.selected{
image = "child-selected"
}else if phonebutton.selected {
image = "phone-selected"
}else if cartbutton.selected {
image = "shopping-cart-selected"
}else if airplanebutton.selected {
image = "travel-selected"
}
let uuid = NSUUID().UUIDString
print("amount is :\(todo.count),image name is :\(image),date is ")
let todos = Todo(id: String(uuid), image: image, date: datepicker.date, title: TodoNameTextfield.text!)
todo.append(todos)
}
测试在viewdidload里面增加定义好的数据也可以显示,oktyped按钮按下后成功的往model里面添加了数据,但是回来主界面却看不到新增的数据;
在界面中新增cell再删除,会出错~
求助!