Swift - 实现tableView单选系统样式
2017-05-31 09:42
225 查看
// 实现tableView单选
import UIKit
class ViewController: UIViewController {
var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height), style: .Plain)
tableView.delegate = self
tableView.dataSource = self
self.view.addSubview(tableView)
}
}
extension ViewController: UITableViewDataSource,UITableViewDelegate {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
cell.textLabel?.text = "123"
return cell
}
//获取将要选择的单元格的路径
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
//取消选中的样式
tableView.deselectRowAtIndexPath(indexPath, animated: true)
//获取当前选中的单元格
let cell:UITableViewCell! = tableView.cellForRowAtIndexPath(indexPath)
//返回所有单元格
//遍历取消所有单元格样式
var arry = tableView.visibleCells
for i in 0 ..< arry.count {
let cells: UITableViewCell = arry[i]
cells.accessoryType = .None
}
//设置选中的单元格样式
cell.accessoryType = .Checkmark
}
}
相关文章推荐
- Swift - 实现tableView单选系统样式
- Swift实现多个TableView侧滑与切换效果
- iOS开发用Tableview实现能改变字体颜色的高仿系统的ActionSheet
- 用swift实现tableview的展示
- 同一个tableview实现多选单选删除
- 使用tableView中的cell来实现单选效果
- tabletableView的单选(系统对勾) 自定义的单选(自定义图片)
- Swift中设置tableview的分割线(separator)的样式、颜色、边距
- Swift TableView实现冻结窗格功能
- 用Swift实现一个TableView,列表上调用LeanCloud的数据。
- iOS项目开发实战——Swift实现多个TableView的侧滑与切换
- Swift - tableView的单元格多选功能的实现(获取多选值、多选删除)
- iOS开发tableView实现单选和复选
- Swift TableView 简单实现冻结窗格功能
- iOS tableView实现单选和多选的实例代码
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- tableview系统cell的4种样式
- swift-tableView 代理方法实现点击按钮删除效果
- TableView中单选的实现
- iOS系统样式下自定义TableView分割线