๐ iOS
Table View Controller
hyebin (Helia)
2022. 12. 28. 17:15
๋ฐ์ํ
ํ ์ด๋ธ ๋ทฐ ์ปจํธ๋กค๋ฌ(Table View Controller)
- ์ฌ์ฉ์์๊ฒ ๋ชฉ๋ก ํํ์ ์ ๋ณด ์ ๊ณต
- ๋ชฉ๋ก์ ํน์ ํญ๋ชฉ์ ์ ํํ์ฌ ์ธ๋ถ ์ฌํญ์ ํ์ํ ๋ ์ ์ฉ
1. Table View Controller ์ถ๊ฐ
๊ธฐ์กด์ View Controller๋ฅผ ์ญ์ ํ ํ, Library์์ Table View Controller๋ฅผ ์ฐพ์ ์คํ ๋ฆฌ ๋ณด๋์ ์ถ๊ฐ
์ถ๊ฐํ Table View Controller๋ฅผ initial View๋ก ์ค์
2. ์ฝ๋ ์์ฑ
Table View์ Cell์ ์๋ณ์๋ฅผ ์ง์
Table View์ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ๋ด์ cellData ๋ฐฐ์ด ์ ์ธ
Table View์ ์น์ ์ ๊ฐ์์ ํ์ ๊ฐ์ ์ค์
Table View์ ๋ฐ์ดํฐ๋ฅผ ๋ํ๋ด๊ธฐ ์ํด ์๋ณ์๋ฅผ ์ฌ์ฉํด cell์ ์ฐพ๊ณ , cell์ ์ด๋ฏธ์ง์ ํ ์คํธ๋ฅผ ํํ
3. ์๋ฎฌ๋ ์ดํฐ ํ์ธ
+ ๋ชฉ๋ก ์ญ์ ํ๊ธฐ
cellData.remove(at: indexPath.row)
override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
return "์ญ์ "
}
+ ๋ชฉ๋ก ์์ ๋ฐ๊พธ๊ธฐ
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let itemToMove = cellData[sourceIndexPath.row]
cellData.remove(at: (sourceIndexPath as NSIndexPath).row)
cellData.insert(itemToMove, at: destinationIndexPath.row)
}
+ ๋ชฉ๋ก ์ถ๊ฐํ๊ธฐ
Table View์ ๋ํ๋ผ ๋ฐ์ดํฐ๋ฅผ ๋ด์ ๋ฐฐ์ด์ ์๋ก์ด ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ ํ, Table View๋ฅผ reloadData() ํ๋ค.
๋ฐ์ํ