我有一個iOS應用程序,我想讓人們在桌面單元上滑動以將該單元格添加到收藏夾頁面tableview。添加單元格到核心數據的收藏夾tableview
它必須使用核心數據,以便在應用程序退出後保存收藏夾。
任何幫助,將不勝感激!
這是我迄今爲止的細胞刷卡動作:
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let favorite = UITableViewRowAction(style: .Normal, title: "Favorite") { (action, indexPath) in
// share item at indexPath
self.editing = false
print("Favorited \(indexPath.row)")
}
favorite.backgroundColor = UIColor.greenColor()
return [favorite]
}
這是我的最愛頁面代碼。
var favorites : [String] = []
override func viewDidLoad() {
super.viewDidLoad()
favorites = vars.favs
self.tableView.reloadData()
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return favorites.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let object = favorites[indexPath.row]
cell.textLabel!.text = object
return cell
}
能否請你告訴我們,你已經完成的工作是什麼? – penatheboss
目前爲止,我只有細胞的滑動動作設置。 – Jacksmackod
如果您有表格視圖,則必須具有一些用於表格視圖的功能。向我們展示 – penatheboss