【发布时间】:2016-08-27 13:49:50
【问题描述】:
您好,我有一个 tableview,这是我在 MyItemTableViewController 类中的代码
var itemList = [String]()
@IBAction func saveItemToList (segue: UIStoryboardSegue) {
let AddNewItemViewController = segue.sourceViewController as! addItemTableViewController
let name = AddNewItemViewController.itemName
if name == "" {
}
else {
itemList.append(name!)
let indexToInsert = itemList.count == 0 ? 0 : itemList.count - 1
let indexPath = NSIndexPath(forRow: indexToInsert, inSection: 0)
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
如何使用 NSUserDefaults 保存我的数组我尝试了一些方法,但对我不起作用。
【问题讨论】:
标签: ios arrays swift nsuserdefaults