質問編集履歴

2

DetailViewController2 のソースコードを追加しました。

2019/06/20 11:07

投稿

harago
harago

スコア11

test CHANGED
File without changes
test CHANGED
@@ -120,7 +120,133 @@
120
120
 
121
121
 
122
122
 
123
+ ### DetailViewController2 のソースコード
124
+
125
+ //
126
+
127
+ // DetailViewController2.swift
128
+
129
+ // projects4
130
+
131
+ //
132
+
133
+ // Created by jiraffe40035 on 2019/06/17.
134
+
135
+ // Copyright © 2019 jiraffe40035. All rights reserved.
136
+
137
+ //
138
+
139
+
140
+
141
+ import UIKit
142
+
143
+
144
+
145
+
146
+
147
+ class DetailViewController2: UIViewController {
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+ @IBOutlet weak var tappedButton: UIImageView!
156
+
157
+
158
+
159
+ override func prepare (for segue: UIStoryboardSegue,sender: Any?){
160
+
161
+ //遷移先のDetailViewController2を取得
162
+
163
+ let detavilViewController2 = segue.destination as! DetailViewController2
164
+
165
+ //タップされたボタンを要素を取得
166
+
167
+ _ = sender as! UIButton;
168
+
169
+ //ボタンタグを取得
170
+
171
+ let buttonTag = tappedButton.tag
172
+
173
+ //詳細画面に表示する画像名を生成
174
+
175
+ let detailImageName = "image" + String(buttonTag)
176
+
177
+ //詳細画面に画像名を渡す
178
+
179
+ detavilViewController2.imageName = detailImageName
180
+
181
+ }
182
+
183
+
184
+
185
+
186
+
187
+ @IBOutlet weak var detailImageView2: UIImageView!
188
+
189
+
190
+
191
+ //①追記
192
+
193
+ var imageName:String?
194
+
195
+
196
+
197
+ override func viewDidLoad() {
198
+
199
+ super.viewDidLoad()
200
+
201
+
202
+
203
+ //②更新
204
+
205
+ guard let myImageName = imageName else{
206
+
207
+ return
208
+
209
+ }
210
+
211
+
212
+
213
+ //myImageNameを用いて画像を指定
214
+
215
+ detailImageView2.image = UIImage (named:myImageName)
216
+
217
+ }
218
+
219
+ //追記
220
+
221
+ //detailImageView2.image = UIImage (named: “image7")
222
+
223
+
224
+
225
+ // Do any additional setup after loading the view.
226
+
227
+ }
228
+
229
+
230
+
231
+
232
+
123
- ### 試したこと
233
+ /*
234
+
235
+ // MARK: - Navigation
236
+
237
+
238
+
239
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
240
+
241
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
242
+
243
+ // Get the new view controller using segue.destination.
244
+
245
+ // Pass the selected object to the new view controller.
246
+
247
+ }
248
+
249
+ */
124
250
 
125
251
 
126
252
 

1

エディタ下のエラーを追加しました。

2019/06/20 11:07

投稿

harago
harago

スコア11

test CHANGED
File without changes
test CHANGED
@@ -12,15 +12,11 @@
12
12
 
13
13
  ### 発生している問題・エラーメッセージ
14
14
 
15
+ 2019-06-20 17:08:11.317438+0900 projects4[29808:2183954] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<projects4.DetailViewController2 0x7fb57850fae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key testImage7.' *** First throw call stack: ( 0 CoreFoundation 0x000000010d8866fb __exceptionPreprocess + 331 1 libobjc.A.dylib 0x000000010bea0ac5 objc_exception_throw + 48 2 CoreFoundation 0x000000010d886269 -[NSException raise] + 9 3 Foundation 0x000000010b915562 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 289 4 UIKitCore 0x000000010fb132d2 -[UIViewController setValue:forKey:] + 87 5 UIKitCore 0x000000010fda08fd -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x000000010d872d41 -[NSArray makeObjectsPerformSelector:] + 305 7 UIKitCore 0x000000010fd9d643 -[UINib instantiateWithOwner:options:] + 1810 8 UIKitCore 0x000000010fb1a3af -[UIViewController _loadViewFromNibNamed:bundle:] + 382 9 UIKitCore 0x000000010fb1ad39 -[UIViewController loadView] + 177 10 UIKitCore 0x000000010fb1b048 -[UIViewController loadViewIfRequired] + 172 11 UIKitCore 0x000000010fb1b868 -[UIViewController view] + 27 12 UIKitCore 0x000000010fa430fc -[_UIFullscreenPresentationController _setPresentedViewController:] + 89 13 UIKitCore 0x000000010fa371f2 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133 14 UIKitCore 0x000000010fb2e4ce -[UIViewController _presentViewController:withAnimationController:completion:] + 3700 15 UIKitCore 0x000000010fb3111b __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98 16 UIKitCore 0x000000010fb31633 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511 17 UIKitCore 0x000000010fb31082 -[UIViewController _presentViewController:animated:completion:] + 172 18 UIKitCore 0x000000010fb312e0 -[UIViewController presentViewController:animated:completion:] + 150 19 UIKitCore 0x00000001102b1eae __74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 133 20 UIKitCore 0x00000001102b6b9f -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 276 21 UIKitCore 0x00000001102b6a5d -[UIStoryboardSegueTemplate _perform:] + 82 22 UIKitCore 0x00000001102b6d1f -[UIStoryboardSegueTemplate perform:] + 157 23 UIKitCore 0x000000011011f204 -[UIApplication sendAction:to:from:forEvent:] + 83 24 UIKitCore 0x000000010fb74c19 -[UIControl sendAction:to:forEvent:] + 67 25 UIKitCore 0x000000010fb74f36 -[UIControl _sendActionsForEvents:withEvent:] + 450 26 UIKitCore 0x000000010fb73eec -[UIControl touchesEnded:withEvent:] + 583 27 UIKitCore 0x0000000110157eee -[UIWindow _sendTouchesForEvent:] + 2547 28 UIKitCore 0x00000001101595d2 -[UIWindow sendEvent:] + 4079 29 UIKitCore 0x0000000110137d16 -[UIApplication sendEvent:] + 356 30 UIKitCore 0x0000000110208293 __dispatchPreprocessedEventFromEventQueue + 3232 31 UIKitCore 0x000000011020abb9 __handleEventQueueInternal + 5911 32 CoreFoundation 0x000000010d7edbe1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 33 CoreFoundation 0x000000010d7ed463 __CFRunLoopDoSources0 + 243 34 CoreFoundation 0x000000010d7e7b1f __CFRunLoopRun + 1231 35 CoreFoundation 0x000000010d7e7302 CFRunLoopRunSpecific + 626 36 GraphicsServices 0x000000011596c2fe GSEventRunModal + 65 37 UIKitCore 0x000000011011dba2 UIApplicationMain + 140 38 projects4 0x000000010b5bb3db main + 75 39 libdyld.dylib 0x000000010ec8e541 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
15
16
 
16
17
 
17
18
 
18
19
 
19
- ```
20
-
21
- Thread 1: signal SIGABRT
22
-
23
- ```
24
20
 
25
21
 
26
22