티스토리 뷰
728x90
반응형

UITableView 를 Swipe 해서 cell 을 remove 해보겠습니다.
코드로 작성해야합니다.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
dataArray.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
}
}
이렇게 작성하면 끝입니다.

잘 나오네요.
전체 코드입니다.
import UIKit
class ViewController3: UIViewController, UITableViewDataSource {
@IBOutlet var myTableView: UITableView!
var dataArray: Array<String> = ["TableView row 0","TableView row 1","TableView row 2"]
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = dataArray[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
dataArray.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
}
}
}
728x90
반응형
'iOS Swift + UIKit' 카테고리의 다른 글
| iOS Swift 테이블뷰 스와이프 버튼 만들기 (TableView swipe button) (0) | 2021.01.25 |
|---|---|
| iOS Swift 테이블뷰 삭제 버튼 이름 변경 (TableView delete button title change) (0) | 2021.01.22 |
| iOS Swift 테이블뷰 라인 없애기 (TableView remove line) (0) | 2021.01.20 |
| iOS Swift 테이블뷰 선택 색상 없애기 (TableView seleted color delete) (0) | 2021.01.19 |
| iOS Swift 화면 안꺼지게 하는 코드, 자동 잠금 방지 (Screen lock disable) 절전모드 (2) | 2021.01.15 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- permission
- 다국어
- Infinite Carousel
- Authorization
- SWIFT
- swiftUI
- AppStore
- 테이블뷰
- 인디케이터
- localizable
- 심사
- 프로그레스
- 로컬라이징
- Xcode
- indicator
- localizing
- 엑스코드
- SKPayment
- presentationcompactadaptation
- TabBar
- 리젝
- 아이오에스
- picker
- TabView
- 현지화
- ios
- 스위프트
- Language
- Reject
- custom segment
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함