【发布时间】:2016-05-29 19:02:22
【问题描述】:
我有一个 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
}
【问题讨论】:
-
你能告诉我们你到目前为止做了什么吗?
-
目前我只有单元格的滑动动作设置。
-
如果你有一个tableview,你必须有一些tableviews的功能。向我们展示这些
-
我会在几分钟内更新问题
-
Penatheboss 初始表格视图是静态的,没有与之关联的代码
标签: swift uitableview favorites