table进阶--单元格交互
2018-06-11 本文已影响9人
iOS_July
delegate:页眉页脚、单元格交互、排序等
闭包:没有名字的函数,一般用于嵌入其他函数之中
值得一提的是cell右部的扩展
public enum UITableViewCellAccessoryType : Int {
case none // don't show any accessory view
case disclosureIndicator // regular chevron. doesn't track 灰色右键
case detailDisclosureButton // info button w/ chevron. tracks 蓝色加圈 详情感叹号
case checkmark // checkmark. doesn't track 蓝色小勾
@available(iOS 7.0, *)
case detailButton // info button. tracks 蓝色加圈 详情感叹号
}
点击cell
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let alertAC = UIAlertController(title: "友情提示", message: "您点击了\n第\(indexPath.row)行的\n ->\(parts[indexPath.row])<-", preferredStyle: .actionSheet)
let action = UIAlertAction(title: "我去过", style: .default) { (_) in
let cell = tableView.cellForRow(at: indexPath)
//右部扩展
cell?.accessoryType = .checkmark
}
let action2 = UIAlertAction(title: "不明白", style: .cancel, handler: nil)
let action3 = UIAlertAction(title: "我是红色哟", style: .destructive, handler: nil)
alertAC.addAction(action)
alertAC.addAction(action2)
alertAC.addAction(action3)
self.present(alertAC, animated: true, completion: nil)
}