質問するログイン新規登録

質問編集履歴

3

更新

2018/12/20 04:09

投稿

KTH
KTH

スコア86

title CHANGED
File without changes
body CHANGED
@@ -56,4 +56,69 @@
56
56
 
57
57
 
58
58
  }
59
- '''
59
+ '''
60
+
61
+
62
+
63
+
64
+ こんなかんじでしょうか?
65
+
66
+ '''
67
+ import UIKit
68
+
69
+ class ViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
70
+
71
+ let city = ["London","Newyork","shanghai","hongkong"]
72
+
73
+ func numberOfComponents(in pickerView: UIPickerView) -> Int {
74
+ return 1
75
+ }
76
+
77
+ func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
78
+ return city.count
79
+ }
80
+
81
+ func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
82
+ return city[row]
83
+
84
+ }
85
+
86
+ func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
87
+
88
+ }
89
+
90
+ @IBOutlet weak var picker: UIPickerView!
91
+
92
+
93
+
94
+ @IBAction func showw(_ sender: AnyObject) {
95
+
96
+ picker.selectedRow(inComponent:0)
97
+ performSegue(withIdentifier: "London", sender: self)
98
+ performSegue(withIdentifier: "Newyork", sender: self)
99
+ performSegue(withIdentifier: "shanghai", sender: self)
100
+ performSegue(withIdentifier: "hongkong", sender: self)
101
+
102
+ let aa:Int = picker.selectedRow(inComponent: 0)
103
+ switch aa {
104
+
105
+ case 0:
106
+ performSegue(withIdentifier: "hongkong", sender: self)
107
+ case 1:
108
+ performSegue(withIdentifier: "sendai", sender: self)
109
+ case 2:
110
+ performSegue(withIdentifier: "shanghai", sender: self)
111
+
112
+ default:
113
+ return
114
+ } }
115
+
116
+ override func viewDidLoad() {
117
+ super.viewDidLoad()
118
+ picker.delegate = self
119
+ picker.dataSource = self
120
+ }
121
+
122
+ }
123
+
124
+ switch文のところはどうすれば正解なのですか?

2

追加

2018/12/20 04:09

投稿

KTH
KTH

スコア86

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  performSegueを使えばそのIdentifierのところへいけるのはわかったのですが、pickerviewの選択したあとどうやれば画面遷移できるのでしょうか?
5
5
 
6
- """import UIKit
6
+ '''import UIKit
7
7
 
8
8
  class ViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
9
9
 
@@ -56,5 +56,4 @@
56
56
 
57
57
 
58
58
  }
59
-
60
- """
59
+ '''

1

"""追加

2018/12/19 09:39

投稿

KTH
KTH

スコア86

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  performSegueを使えばそのIdentifierのところへいけるのはわかったのですが、pickerviewの選択したあとどうやれば画面遷移できるのでしょうか?
5
5
 
6
- import UIKit
6
+ """import UIKit
7
7
 
8
8
  class ViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
9
9
 
@@ -55,4 +55,6 @@
55
55
  }
56
56
 
57
57
 
58
- }
58
+ }
59
+
60
+ """