Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 신도림 테크노마트
- 보라카이
- Xcode
- swift
- UITableView
- 공략
- loop
- 포켓볼
- 아이폰7
- LG유플러스
- 페이백
- 해몽
- push
- UIView
- error
- 스마트폰
- IOS
- 포켓몬 GO
- 샘플
- setting
- Bitcode
- swift3
- 신도림
- afterdelay
- 앱스토어
- Check
- simulator
- GCD
- Example
- 얻는법
Archives
- Today
- Total
도래울
swift uitableview checkbox example 본문
Try this:
var checked = [Bool]() // Have an array equal to the number of cells in your table
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
//configure you cell here.
if !checked[indexPath.row] {
cell.accessoryType = .None
} else if checked[indexPath.row] {
cell.accessoryType = .Checkmark
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.accessoryType == .Checkmark {
cell.accessoryType = .None
checked[indexPath.row] = false
} else {
cell.accessoryType = .Checkmark
checked[indexPath.row] = true
}
}
}To reset all the checkboxes:
func resetChecks() {
for i in 0.. < tableView.numberOfSections {
for j in 0.. < tableView.numberOfRowsInSection(i) {
if let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: j, inSection: i)) {
cell.accessoryType = .None
}
}
}
}'개발 > iOS' 카테고리의 다른 글
| remove all subviews of a view in Swift (0) | 2016.07.13 |
|---|---|
| swift for in loop (0) | 2016.07.13 |
| Swift string replace (0) | 2016.07.12 |
| Swift 배열과 딕셔너리 (0) | 2016.07.12 |
| [Swift] NSDateFormatter로 NSDate와 문자열 한국 날짜포맷 생성 (0) | 2016.07.08 |
Comments