【发布时间】:2015-01-12 14:40:32
【问题描述】:
我在我的应用中添加了一个 UITableView。此表格视图包含单元格,如果它们向左滑动,则会显示一些自定义编辑按钮(通过此函数:editActionsForRowAtIndexPath)。我想知道哪个 UITableViewCell 向左滑动或显示自定义编辑选项并将默认文本设置为该单元格中的 detailText 标签。
进一步解释:
我有几个 UITableViewCells。用户滑动这些单元格之一。现在单元格处于编辑模式并显示我添加的编辑选项(名为“日期”)。用户按下此按钮/选项(日期)。现在一个 datePicker 正在弹出。用户选择了一个日期。这个日期写在标签上。这个 dateLabel 应该被传输到被刷过的单元格的 detailTextLabel 中。问题是我不知道如何将带有日期的标签传输到被刷过的单元格的 detailTextLabel。
我希望有人可以帮助我。我正在使用 Swift 编码。
如果 UITableViewCell 向左滑动,这是我的自定义选项代码:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let editingCell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
let date = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Date", handler: { (action, indexPath) -> Void in
self.showSideBar(true)
self.delegate?.sideBarWillOpen?()
self.isEditingStyle = true
})
date.backgroundColor = UIColor(red: 0.204, green:0.667, blue:0.863, alpha: 1.0);
return [date];
}
日期选择器:
func datePickerChanged(datePicker:UIDatePicker) {
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = NSDateFormatterStyle.ShortStyle
dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
var strDate = dateFormatter.stringFromDate(datePicker.date)
dateLabel.text = strDate
}
在detailTextLabel中添加日期:
lastEditedCell?.detailTextLabel?.text = dateLabel
【问题讨论】:
-
使用 viewController 中的引用来跟踪滑动单元格:
weak var lastCellEdited:UITableViewCell?
标签: ios uitableview swift xcode6