質問編集履歴

3

VCの詳細を記入

2018/12/26 05:50

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -36,132 +36,244 @@
36
36
 
37
37
 
38
38
 
39
- ##対象コード1
39
+ ##対象コード
40
+
41
+ ViewController_r3、ViewController_r4のようにこの形のものが残り3つほどが画面遷移でつながっています。
42
+
43
+ この全てのVC間で出来ずにいます。下記のコードは一部です。
44
+
45
+ ```swift
46
+
47
+ var r3answer:Int = 0
48
+
49
+
50
+
51
+ class ViewController_r3:UIViewController{
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+ override func loadView(){
60
+
61
+ let view = UIView()
62
+
63
+ view.frame = CGRect(x:0, y:0, width:375, height:669)
64
+
65
+ view.backgroundColor = .white
66
+
67
+ self.view = view
68
+
69
+
70
+
71
+ let image1:UIImage = UIImage(named:"画像")!
72
+
73
+ let imageView1 = UIImageView(image:image1)
74
+
75
+
76
+
77
+ let screenWidth:CGFloat = view.frame.size.width
78
+
79
+ let screenHeight:CGFloat = view.frame.size.height
80
+
81
+
82
+
83
+ imageView1.center = CGPoint(x:screenWidth/2, y:screenHeight/2)
84
+
85
+ imageView1.frame = CGRect(x:85, y:150, width:200, height:200)
86
+
87
+ view.addSubview(imageView1)
88
+
89
+
90
+
91
+ let btn_r31 = UIButton()
92
+
93
+ btn_r31.frame = CGRect(x:110, y:450, width:150, height:50)
94
+
95
+ btn_r31.setTitle("見た", for:.normal)
96
+
97
+ btn_r31.setTitleColor(UIColor.white, for:.highlighted)
98
+
99
+ btn_r31.backgroundColor = .blue
100
+
101
+ btn_r31.layer.cornerRadius = 20.0
102
+
103
+ btn_r31.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
104
+
105
+ btn_r31.tag = 1
106
+
107
+ view.addSubview(btn_r31)
108
+
109
+
110
+
111
+ let btn_r32 = UIButton()
112
+
113
+ btn_r32.frame = CGRect(x:110, y:510, width:150, height:50)
114
+
115
+ btn_r32.setTitle("見ていない", for:.normal)
116
+
117
+ btn_r32.setTitleColor(UIColor.white, for:.highlighted)
118
+
119
+ btn_r32.backgroundColor = .blue
120
+
121
+ btn_r32.layer.cornerRadius = 20.0
122
+
123
+ btn_r32.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
124
+
125
+ btn_r32.tag = 2
126
+
127
+ view.addSubview(btn_r32)
128
+
129
+
130
+
131
+
132
+
133
+ }
134
+
135
+ @objc func onClick(_ sender:UIButton){
136
+
137
+ print(sender.tag);
138
+
139
+
140
+
141
+ let nextvc = ViewController_r4() //ここにエラーが出ます
142
+
143
+ if sender.tag == 2 {
144
+
145
+ r3answer = 0
146
+
147
+ }
148
+
149
+ self.present(nextvc, animated:true, completion: nil)
150
+
151
+
152
+
153
+ }
154
+
155
+ @objc func tappB(_ sender:UIButton){
156
+
157
+
158
+
159
+ let nextvc = ViewController_r3()
160
+
161
+
162
+
163
+ self.present(nextvc, animated: true, completion: nil)
164
+
165
+ }
166
+
167
+
168
+
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+ var r4answer:Int = 0
176
+
177
+ class ViewController_r4:UIViewController {
178
+
179
+
180
+
181
+ override func loadView() {
182
+
183
+
184
+
185
+ let view = UIView()
186
+
187
+ view.frame = CGRect(x:0, y:0, width:375, height:669)
188
+
189
+ view.backgroundColor = .white
190
+
191
+ self.view = view
192
+
193
+
194
+
195
+ let image2:UIImage = UIImage(named:"画像")!
196
+
197
+ let imageView2 = UIImageView(image:image2)
198
+
199
+
200
+
201
+ let screenWidth:CGFloat = view.frame.size.width
202
+
203
+ let screenHeight:CGFloat = view.frame.size.height
204
+
205
+
206
+
207
+ imageView2.center = CGPoint(x:screenWidth/2, y:screenHeight/2)
208
+
209
+ imageView2.frame = CGRect(x:70, y:150, width:220, height:230)
210
+
211
+ view.addSubview(imageView2)
212
+
213
+
214
+
215
+ let btn_r41 = UIButton()
216
+
217
+ btn_r41.frame = CGRect(x:110, y:450, width:150, height:50)
218
+
219
+ btn_r41.setTitle("見た", for:.normal)
220
+
221
+ btn_r41.setTitleColor(UIColor.white, for:.highlighted)
222
+
223
+ btn_r41.backgroundColor = .blue
224
+
225
+ btn_r41.layer.cornerRadius = 20.0
226
+
227
+ btn_r41.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
228
+
229
+ btn_r41.tag = 1
230
+
231
+ view.addSubview(btn_r41)
232
+
233
+
234
+
235
+ let btn_r42 = UIButton()
236
+
237
+ btn_r42.frame = CGRect(x:110, y:510, width:150, height:50)
238
+
239
+ btn_r42.setTitle("見ていない", for:.normal)
240
+
241
+ btn_r42.setTitleColor(UIColor.white, for:.highlighted)
242
+
243
+ btn_r42.backgroundColor = .blue
244
+
245
+ btn_r42.layer.cornerRadius = 20.0
246
+
247
+ btn_r42.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
248
+
249
+ btn_r42.tag = 2
250
+
251
+ view.addSubview(btn_r42)
252
+
253
+
254
+
255
+ }
256
+
257
+ @objc func onClick(_ sender:UIButton){
258
+
259
+ print(sender.tag);
260
+
261
+
262
+
263
+ let nextvc = ViewController_r5()
264
+
265
+ if sender.tag == 2 {
266
+
267
+ r4answer = 0
268
+
269
+ }
270
+
271
+ self.present(nextvc, animated: true, completion: nil)
272
+
273
+ }
274
+
275
+
276
+
277
+ }
40
278
 
41
279
  ```
42
-
43
- var r3answer:Int = 0
44
-
45
-
46
-
47
- class ViewController_r3:UIViewController{
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
- override func loadView(){
56
-
57
- let view = UIView()
58
-
59
- view.frame = CGRect(x:0, y:0, width:375, height:669)
60
-
61
- view.backgroundColor = .white
62
-
63
- self.view = view
64
-
65
-
66
-
67
- let image1:UIImage = UIImage(named:"画像")!
68
-
69
- let imageView1 = UIImageView(image:image1)
70
-
71
-
72
-
73
- let screenWidth:CGFloat = view.frame.size.width
74
-
75
- let screenHeight:CGFloat = view.frame.size.height
76
-
77
-
78
-
79
- imageView1.center = CGPoint(x:screenWidth/2, y:screenHeight/2)
80
-
81
- imageView1.frame = CGRect(x:85, y:150, width:200, height:200)
82
-
83
- view.addSubview(imageView1)
84
-
85
-
86
-
87
- let btn_r31 = UIButton()
88
-
89
- btn_r31.frame = CGRect(x:110, y:450, width:150, height:50)
90
-
91
- btn_r31.setTitle("見た", for:.normal)
92
-
93
- btn_r31.setTitleColor(UIColor.white, for:.highlighted)
94
-
95
- btn_r31.backgroundColor = .blue
96
-
97
- btn_r31.layer.cornerRadius = 20.0
98
-
99
- btn_r31.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
100
-
101
- btn_r31.tag = 1
102
-
103
- view.addSubview(btn_r31)
104
-
105
-
106
-
107
- let btn_r32 = UIButton()
108
-
109
- btn_r32.frame = CGRect(x:110, y:510, width:150, height:50)
110
-
111
- btn_r32.setTitle("見ていない", for:.normal)
112
-
113
- btn_r32.setTitleColor(UIColor.white, for:.highlighted)
114
-
115
- btn_r32.backgroundColor = .blue
116
-
117
- btn_r32.layer.cornerRadius = 20.0
118
-
119
- btn_r32.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
120
-
121
- btn_r32.tag = 2
122
-
123
- view.addSubview(btn_r32)
124
-
125
-
126
-
127
-
128
-
129
- }
130
-
131
- @objc func onClick(_ sender:UIButton){
132
-
133
- print(sender.tag);
134
-
135
-
136
-
137
- let nextvc = ViewController_r4() //ここにエラーが出ます
138
-
139
- if sender.tag == 2 {
140
-
141
- r3answer = 0
142
-
143
- }
144
-
145
- self.present(nextvc, animated:true, completion: nil)
146
-
147
-
148
-
149
- }
150
-
151
- @objc func tappB(_ sender:UIButton){
152
-
153
-
154
-
155
- let nextvc = ViewController_r3()
156
-
157
-
158
-
159
- self.present(nextvc, animated: true, completion: nil)
160
-
161
- }
162
-
163
-
164
-
165
- }
166
-
167
- ```

2

URLを消しました

2018/12/26 05:50

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- [初歩的質問]画面遷移のエラーの修正方法を教えていただきたいです。
1
+ [初歩的質問]画面遷移のエラー
test CHANGED
@@ -64,7 +64,7 @@
64
64
 
65
65
 
66
66
 
67
- let image1:UIImage = UIImage(named:"042802.jpg")!
67
+ let image1:UIImage = UIImage(named:"画像")!
68
68
 
69
69
  let imageView1 = UIImageView(image:image1)
70
70
 

1

修正依頼のところを修正

2018/12/26 05:37

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- [超初歩的質問]変数宣言につ
1
+ [超初歩的質問]画面遷移エラーの修正方法を教えてただきたいです。
test CHANGED
@@ -14,23 +14,31 @@
14
14
 
15
15
 
16
16
 
17
+ 今困っているのは、変数をVC間に記入していると「Use of unresolved identifier...」と
18
+
19
+ 実行できずこのエラーが出てしまいます。
20
+
21
+ これを修正し、画面遷移とこのtagがしっかり判定されているのを確認したいのですが、
22
+
23
+ 修正方法がわかりません。教えていただきたいです。
24
+
25
+
26
+
17
27
  ##エラー
18
28
 
19
29
 
20
30
 
21
31
  VCのUIButtonによる画面遷移で次のVCに遷移が出来ないでいます。
22
32
 
23
- Use of unresolved identifier 'ViewController_r5'
33
+ Use of unresolved identifier 'ViewController_r4'
24
34
 
25
35
 
26
36
 
27
37
 
28
38
 
29
- ##対象コード
39
+ ##対象コード1
30
40
 
31
- ```swift```
41
+ ```
32
-
33
-
34
42
 
35
43
  var r3answer:Int = 0
36
44
 
@@ -38,7 +46,11 @@
38
46
 
39
47
  class ViewController_r3:UIViewController{
40
48
 
49
+
41
50
 
51
+
52
+
53
+
42
54
 
43
55
  override func loadView(){
44
56
 
@@ -52,7 +64,7 @@
52
64
 
53
65
 
54
66
 
55
- let image1:UIImage = UIImage(named:"画像")!
67
+ let image1:UIImage = UIImage(named:"042802.jpg")!
56
68
 
57
69
  let imageView1 = UIImageView(image:image1)
58
70
 
@@ -122,7 +134,7 @@
122
134
 
123
135
 
124
136
 
125
- let nextvc = ViewController_r4()
137
+ let nextvc = ViewController_r4() //ここにエラーが出ます
126
138
 
127
139
  if sender.tag == 2 {
128
140
 
@@ -152,112 +164,4 @@
152
164
 
153
165
  }
154
166
 
155
- var r4answer:Int = 0
156
-
157
- class ViewController_r4:UIViewController {
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
- override func loadView() {
166
-
167
-
168
-
169
- let view = UIView()
170
-
171
- view.frame = CGRect(x:0, y:0, width:375, height:669)
172
-
173
- view.backgroundColor = .white
174
-
175
- self.view = view
176
-
177
-
178
-
179
- let image2:UIImage = UIImage(named:"画像")!
180
-
181
- let imageView2 = UIImageView(image:image2)
182
-
183
-
184
-
185
- let screenWidth:CGFloat = view.frame.size.width
186
-
187
- let screenHeight:CGFloat = view.frame.size.height
188
-
189
-
190
-
191
- imageView2.center = CGPoint(x:screenWidth/2, y:screenHeight/2)
192
-
193
- imageView2.frame = CGRect(x:70, y:150, width:220, height:230)
194
-
195
- view.addSubview(imageView2)
196
-
197
-
198
-
199
- let btn_r41 = UIButton()
200
-
201
- btn_r41.frame = CGRect(x:110, y:450, width:150, height:50)
202
-
203
- btn_r41.setTitle("見た", for:.normal)
204
-
205
- btn_r41.setTitleColor(UIColor.white, for:.highlighted)
206
-
207
- btn_r41.backgroundColor = .blue
208
-
209
- btn_r41.layer.cornerRadius = 20.0
210
-
211
- btn_r41.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
212
-
213
- btn_r41.tag = 1
214
-
215
- view.addSubview(btn_r41)
216
-
217
-
218
-
219
- let btn_r42 = UIButton()
220
-
221
- btn_r42.frame = CGRect(x:110, y:510, width:150, height:50)
222
-
223
- btn_r42.setTitle("見ていない", for:.normal)
224
-
225
- btn_r42.setTitleColor(UIColor.white, for:.highlighted)
226
-
227
- btn_r42.backgroundColor = .blue
228
-
229
- btn_r42.layer.cornerRadius = 20.0
230
-
231
- btn_r42.addTarget(self, action:#selector(onClick(_:)), for:.touchUpInside)
232
-
233
- btn_r42.tag = 2
234
-
235
- view.addSubview(btn_r42)
236
-
237
-
238
-
239
- }
240
-
241
- @objc func onClick(_ sender:UIButton){
242
-
243
- print(sender.tag);
244
-
245
-
246
-
247
- let nextvc = ViewController_r5()
248
-
249
- if sender.tag == 2 {
250
-
251
- r4answer = 0
252
-
253
- }
254
-
255
- self.present(nextvc, animated: true, completion: nil)
256
-
257
- }
258
-
259
-
260
-
261
- }
262
-
263
167
  ```