点击编辑没有添加成功 进行了调试 由于只是初学不懂是什么意思
uuid 和todo是否没取到值
如果没有 那需要怎么修改
var image = ""
if "" == image {
image = "selected-child"
}
if todo == nil {
let uuid = NSUUID().UUIDString
let todo = TodoModel(id: uuid, image: image, title: todoItem.text!, date: todoDate.date)
todos.append(todo)
}
else {
todo?.image = image
todo?.title = todoItem.text!
todo?.date = todoDate.date
}
let image = "selected-child"
var todo:TodoModel?
if todo == nil {
let uuid = UIDevice().identifierForVendor?.UUIDString
todo = TodoModel(id: uuid, image: image, title: todoItem.text!, date: todoDate.date)
}else{
todo?.image = image
todo?.title = todoItem.text!
todo?.date = todoDate.date
}
1、ViewController.swift中
class ViewController: UIViewController , UITableViewDataSource , UITableViewDelegate{
//全局变量 定义本地运行时的数据库(移动到这里了)
static var todos:[TodoModel]?
// 添加这个用来让确定返回
@IBAction func UnwindToMain(sender: UIStoryboardSegue)
{
}
override func viewDidAppear(animated: Bool) {
tableView.reloadData()
}
@IBOutlet weak var tableView: UITableView!
.........
修改下面所有的 todos 为 ViewController.todos
2、DetailViewController.swift 中
(你需要在storyboard中control拖拽确定到 这个VC的exit上面,最上面一排最右边一个)
修改todos 为 ViewController.todos
if todo == nil {
let uuid = NSUUID().UUIDString
// 这里改变了
todo = TodoModel(id: uuid, image: image, title: todoItem.text!, date: todoDate.date)
ViewController.todos!.append(todo!)
}
3、添加功能正常了。
4、关于修改功能,选中liestview项编辑,需要在DetaiViewController中使用segue查看传入的todos数组的索引号,然后修改todos,这部分我没有做。
Github上已经提交。