Notice
Recent Posts
Recent Comments
Link
ยซ   2024/05   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

lgvv98

Table - ์ฝ”๋“œ๋ฆฌ๋ทฐ ( ํ…Œ์ด๋ธ”๋ทฐ์ปจํŠธ๋กค๋Ÿฌ ) ๋ณธ๋ฌธ

โš ๏ธ deprecated โš ๏ธ/Doit ์•„์ดํฐ ์•ฑ(์ž…๋ฌธ)

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)])
        }
    }

}
	
Comments