티스토리 뷰

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//ViewController
 
 
import UIKit
 
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
 
    @IBOutlet weak var picker: UIPickerView!
    @IBOutlet weak var label: UILabel!
    var selectRow = 0
    var Array = ["Red","Blue","White","Black","Pupple"]
    
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        picker.delegate = self
        picker.dataSource = self
       
    }
 
    // 뭘 보여줄거냐
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int-> String? {
        return Array[row]
    }
    // 총 갯수
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int-> Int {
        return Array.count
    }
    // 몇개씩 보여줄꺼냐?
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }
    // 선택한 Array의 row값을 가져오기 위해서 초기값인 selectRow에 해당 row를 가져옴
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        selectRow = row
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
 
 
    
    @IBAction func buttonTapped(sender: AnyObject) {
    
    label.text = Array[selectRow]
    }
    
    
    
    
}
 
 
 
cs


저작자 표시 비영리 변경 금지
신고
Creative Commons License
Creative Commons License
댓글
댓글쓰기 폼
공지사항
최근에 달린 댓글
Total
2,824
Today
0
Yesterday
8
링크
«   2017/04   »
            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            
글 보관함