์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- Lv2
- TCA
- ํ๋ก๊ทธ๋๋จธ์ค
- combine
- swift
- visionOS
- BOJ
- node.js
- tableView
- Xcode
- MVVM
- reactorkit
- SwiftUI
- ios
- designpattern
- Kuring
- XCTest
- rxcocoa
- SnapKit
- BFS
- RxSwift
- Swfit
- arkit
- realm
- CollectionView
- ํจ์คํธ์บ ํผ์ค
- ๋ฐฑ์ค
- UIKit
- Flutter
- raywenderlich
- Today
- Total
lgvv98
Table - ์ฝ๋๋ฆฌ๋ทฐ ( ํ ์ด๋ธ๋ทฐ์ปจํธ๋กค๋ฌ ) ๋ณธ๋ฌธ
Table - ์ฝ๋๋ฆฌ๋ทฐ ( ํ ์ด๋ธ๋ทฐ์ปจํธ๋กค๋ฌ )
๐ฅ ์บ๋ฟ๋งจ 2021. 3. 2. 13:35ํ ์ด๋ธ ๋ทฐ -- ์ด๊ฑฐ ์ง์ง ๋ง์ด ์ฌ์ฉํ ๊ฒ ๊ฐ์๋ฐ, ์ฃผ์ ํตํด์ ํ์คํ ์์๋๊ธฐ
์ ๊ทธ๋ฆฌ๊ณ ์ด๊ฑด ๊ฐ์๊ธฐ ์๊ฐ๋์ ์ ๋๊ฑด๋ฐ IBOutlet์ ์ง์ ์ ๋ฌํ ์๊ฐ ์์ด์
๋ฐ๋ก ๋ณ์ ์ ์ธํด์ ์ฐ๊ฒฐํด ์ฃผ์ด์ผํ๋ค.
ํ ์ด๋ธ ๋ทฐ ๋ณด๋ฉด ์ ๊ธฐ ๊ณ์ ์ค์ด ๋ณด์ด์ฃ ? ๊ทผ๋ฐ ์ ๊ฑฐ ์์ผ๋ฉด ๋ถํธํ์์์ ๊ทธ์ตธ? ๊ทธ๋ฌ๋ฉด ์ด๋ป๊ฒ ํด๊ฒฐํด์ผ ํ๋๋ฉด
ํ ์ด๋ธ ๋ทฐ์ ํ๋กํ ํ์ ์๋์ view๋ฅผ ํ๋ ๋ฃ์ด์ฃผ๋ฉด ํ ์ด๋ธ ๋ทฐ์์ ๋ด์ฉ์ด ์์ ๋, ๋์ด์ ํ์๋์ง ์์์! -- ๊ฟํ
ํ ์ด๋ธ ๋ทฐ ์ฌ์ฉ๋ฒ์,, ์๋ ์ค์ํ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์ด์ ์ฐ์ ์ดํด๋ณด๋๋ก ํ์.
์ฃผ์๋ณด๋ฉด์ ๋ณต์ตํ๋ฉด ์ฌ์
๊ทธ๋๋ ์ฌ์ฉ๋ฒ ๊ฐ๋จ์ ๋ฆฌ๋ ํ๊ณ ์ง๋๊ฐ๊น์?
ํ ์ด๋ธ ๋ทฐ ๊ธฐ์ด ์ฌ์ฉ๋ฒ
1. ๋ฐ์ดํฐ์์ค ๋ฐ ๋ธ๋ฆฌ๊ฒ์ด์ class์ชฝ์ ์์ฑ
2. ๊ทธ ์ดํ๋.. ํจ์ ๊ธ๋ฐฉ ์ดํดํ ์ ์์.
์ ๊ทผ๋ฐ ์ฌ๊ธฐ์ basic ๊ฐ๋ ์ถ๊ฐ
๋ง์ฝ ๋ด ๋ฐ์ดํฐ๊ฐ 200๊ฐ๊ณ ํ๋ฉด์ 10๊ฐ๋ง ํ์๋๋ค๊ณ ํ๋ฉด
์ฌ์ฌ์ฉํ์ธ๊ฐ? ์ฌํผ ์ฌ์ฌ์ฉํ๊ฒ ๋๋๋ฐ
ํ๋ฉด์ ํ์๋๋ ๊ฒ๋ง ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฆฌ๊ณ ๋๋จธ์ง๋ ์ฌ๋ฆฌ์ง ์๋๋ค. ํ๋ฉด์ ๋ํ๋์ผ ํ ๋ ๋ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฆฌ๊ณ
์ฌ๋ผ์ง๋ ๊ฒ์ ์ฌ์ฌ์ฉํ์ ๋ฃ์ด์ ๊ฐ๊ณ ์๋ ๊ฒ์ผ๋ก ์์
iOS๊ฐ ๋ฉ๋ชจ๋ฆฌ๊ฐ ์ ์ด๋ ์ ๊ด๋ฆฌํ๋๋ฐ๋ ์ด๋ฐ ์ด์ ๊ฐ ์๋ค๊ณ ํด
๊ฑฐ๋์ ๋ฏธํ๊ณ , ์ด ๊ฐ๋ ์ ๋ด ๊นํ๋ธ Basic ํธ์ ๊ฐ๋ฉด ๊ณต๋ถํ ์ฝ๋๊ฐ ์์ผ๋๊น ์ง์ ์ฐพ์๋ณด๋๋ก
์๋๋ฉด ๋์ค์ ์์ ํ๋๋ก ํ ๊ฒ
//
// DetailViewController.swift
// Table
//
// Created by Hamlit Jason on 2021/02/25.
//
import UIKit
class DetailViewController: UIViewController {
var receiveItem = ""
@IBOutlet var lblItem: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
lblItem.text = receiveItem
// Do any additional setup after loading the view.
}
func receiveItem(_ item : String){
receiveItem = item
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
//
// AddViewController.swift
// Table
//
// Created by Hamlit Jason on 2021/02/25.
//
import UIKit
let MAX_ARRAY_NUM = 3
let PICKER_VIEW_COMUMN = 1
let PICKER_VIEW_HEIGHT:CGFloat = 40
var imageArray = [UIImage?]()
var imageFileName = [ "cart.png", "clock.png", "pencil.png" ]
var fileName = ""
class AddViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return imageFileName.count
}
/*
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return itemsImageFile[row]
}
*/
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let imageView = UIImageView(image: imageArray[row])
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 150)
return imageView
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
imgView.image = imageArray[row]
fileName = imageFileName[row]
}
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return CGFloat(80)
}
@IBOutlet var tfAddItem: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
for i in 0 ..< MAX_ARRAY_NUM {
let image = UIImage(named: imageFileName[i])
imageArray.append(image!)
}
imgView.image = imageArray[0]
fileName = imageFileName[0]
}
@IBAction func btnAddItem(_ sender: UIButton) {
items.append(tfAddItem.text!)
itemsImageFile.append(fileName)
tfAddItem.text="" // ํ
์คํธํ๋์ ๋ด์ฉ์ ์ง์ด๋ค.
_ = navigationController?.popViewController(animated: true) // ๋ด๋น๊ฒ์ด์
์ ๋ฃจํธ๋ทฐ๋ก ๋์๊ฐ๋ค.
// ๊ทผ๋ฐ ์ฌ๊ธฐ ์ด๊ฒ๋ง์ผ๋ก๋ ์ด์ ๋ทฐ๊ฐ ์
๋ฐ์ดํธ๊ฐ ์๋์ ๋ทฐ์์ดํผ์ด๋ฅผ ํ
์ด๋ธ ๋ทฐ ์ปจํธ๋กค๋ฌ์ ์ถ๊ฐํ๋ค.
}
@IBOutlet var imgView: UIImageView!
@IBOutlet var imgPicker: UIPickerView!
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
//
// TableViewController.swift
// Table
//
// Created by Hamlit Jason on 2021/02/25.
//
import UIKit
var items = ["์ฑ
๊ตฌ๋งค", "์ฒ ์์ ์ฝ์", "์คํฐ๋ ์ค๋นํ๊ธฐ"] // ์ฌ๊ธฐ์ ๋ ํ๋์ ์ค์ํ ๊ฐ๋
!! ๋ค๋ฅธ ์ค์ํํธ ํ์ผ์์๋ ์ฐธ์กฐํ๋ ค๋ฉด ํด๋์ค ๋ฐ์๋ค๊ฐ ์ ์ธํด๋์ด์ผ ํ๋ค.
var itemsImageFile = ["cart.png","clock.png","pencil.png"]
class TableViewController: UITableViewController {
@IBOutlet var tvListView: UITableView!
/* ์ฐธ๊ณ
๋ทฐ ๋๋๋ก๋ - ๋ทฐ๊ฐ ๋ก๋ ๋์์ ๋, ์ฆ, ๋ทฐ๊ฐ ์์ฑ๋ ๋ ํ๋ฒ๋ง ํธ์ถ๋๋ค.
๋ทฐ ์์ดํผ์ด - ๋ทฐ๊ฐ ๋
ธ์ถ๋ ์ค๋น๊ฐ ๋๋ฌ์ ๋ ,๋ทฐ๊ฐ ๋
ธ์ถ๋ ๋๋ง๋ค
๋ทฐ ๋๋์ดํผ์ด - ๋ทฐ๊ฐ ์์ ํ ๋ณด์ธ ํ ํธ์ถ๋๋ ํจ์, ๋ทฐ๊ฐ ์์ ํ ๋ณด์ธ ํ ํธ์ถ๋๋ค.
*/
override func viewDidLoad() {
super.viewDidLoad()
for i in itemsImageFile {
let image = UIImage(named: i)
imageArray.append(image)
}
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.leftBarButtonItem = self.editButtonItem // ๋ฉ์ธ ์คํ ๋ฆฌ๋ณด๋์ ๋ฐ๋ก ์ถ๊ฐํ์ง ์์๋ ๋๋ค. ์ผ์ชฝ ๋ฐ๋ฒํผ ์์ดํ
์ฌ์ฉํ๋ ์ฝ๋์ด๋ค.
}
override func viewWillAppear(_ animated: Bool) {
tvListView.reloadData() // ํ
์ด๋ธ ๋ทฐ๋ฅผ ๋ค์ ๋ถ๋ฌ์จ๋ค. ์ฆ, ํ
์ด๋ธ๋ทฐ์ ๋ณ๊ฒฝ์ฌํญ์ด ์์ผ๋ฉด ๋ฐ์ํ๋ค.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1 //๋ณดํต์ ํ
์ด๋ธ์์ ์น์
์ด ํ๊ฐ์ด๋ฏ๋ก ์ผ๋จ 1๋กํ๋ค.
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return items.count // ์น์
๋น ์ด์ ์๋ ์์ดํ
์ ๊ฐ์์ด๋ฏ๋ก ์์ดํ
์ ๊ฐฏ์๋ฅผ ๋ฆฌํดํ๋ค.
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
cell.textLabel?.text = items[(indexPath as NSIndexPath).row]
cell.imageView?.image = UIImage(named: itemsImageFile[(indexPath as NSIndexPath).row])
// Configure the cell...
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
// ์์ผ๋ก ๋ฐ์์๋ ์ญ์ ํ๋ ์ฝ๋
if editingStyle == .delete {
// Delete the row from the data source
items.remove(at: (indexPath as NSIndexPath).row)
itemsImageFile.remove(at: (indexPath as NSIndexPath).row)
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
return "์ญ์ " // ์ผ์ชฝ์ผ๋ก ๋ฐ์์๋ ๋๋ฆฌํธ๋ฅผ ํ๊ธ๋ก ์ญ์ ๋ผ๊ณ ๋จ๊ฒ ๋ง๋๋ ์ฝ๋
}
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
// ๋ชฉ๋ก์ ๋๋๊ทธํ์ฌ ์์น๋ฅผ ๋ฐ๊พธ๋ ํจ์์ด๋ค.
let itemToMove = items[(fromIndexPath as NSIndexPath).row] // ์ด๋ํ ์์ดํ
์ ์์น
let itemImageToMove = itemsImageFile[(fromIndexPath as NSIndexPath).row] // ์ด๋ํ ์์ดํ
์ ์ด๋ฏธ์ง
items.remove(at: (fromIndexPath as NSIndexPath).row) // ์ด๋ํ ์์ดํ
์ ์ญ์ - ์ด๋!!! ๋ค์ ์์ดํ
์ ์ธ๋ฑ์ค๋ ์ฌ์ ๋ ฌ๋๋ค.
itemsImageFile.remove(at: (fromIndexPath as NSIndexPath).row) // ์ด๋ํ ์ด๋ฏธ์ง ์ญ์ - ์ด๋!!! ๋ค์ ์ด๋ฏธ์ง์ ์ธ๋ฑ์ค๋ ์ฌ์ ๋ ฌ๋๋ค.
items.insert(itemToMove, at: (to as NSIndexPath).row) // ์ญ์ ๋ ์์ดํ
์ ์ฝ์
- ์ด๋!! ์ฝ์
ํ ์ธ๋ฑ์ค๋ ์ฌ์ ๋ ฌ๋๋ค.
itemsImageFile.insert(itemImageToMove, at: (to as NSIndexPath).row) // ์ญ์ ๋ ์ด๋ฏธ์ง ์ฝ์
- ์ด๋!! ์ฝ์
ํ ์ธ๋ฑ์ค๋ ์ฌ์ ๋ ฌ๋๋ค.
}
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
NSLog("asd")
if segue.identifier == "sgDetail" {
let cell = sender as! UITableViewCell // ์ผ๋๊ฐ any ํ์
์ด๋ผ์ ์บ์คํ
ํด์ cell์ ์ ์ธํ๊ณ
let indexPath = self.tvListView.indexPath(for: cell) //
let detailView = segue.destination as! DetailViewController
detailView.receiveItem(items[((indexPath! as NSIndexPath).row)])
}
}
}
'โ ๏ธ deprecated โ ๏ธ > Doit ์์ดํฐ ์ฑ(์ ๋ฌธ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Navigation - ์ฝ๋๋ฆฌ๋ทฐ (0) | 2021.03.02 |
---|---|
Tab - ์ฝ๋๋ฆฌ๋ทฐ (ํญ๋ฐ ์ปจํธ๋กค๋ฌ) (0) | 2021.03.02 |
PageControl - ์ฝ๋๋ฆฌ๋ทฐ (0) | 2021.03.02 |
Map - ์ฝ๋๋ฆฌ๋ทฐ(๋งต๋ทฐ) (0) | 2021.03.02 |
Web - ์ฝ๋๋ฆฌ๋ทฐ(์น๋ทฐ) (0) | 2021.03.02 |