前提・実現したいこと
Xcodeでswiftを書いているのですが、複数の画面を作り、画面遷移させようとするとトップ→Aページは成功するが。
Aページ→Bページやトップ→Bページへの遷移時画面が固まりエラーになる。
かなり初心者ですので咀嚼してご教示いただけると幸いです。
発生している問題・エラーメッセージ
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)
該当のソースコード
swift
1// 2// AppDelegate.swift 3// projects4 4// 5// Created by jiraffe40035 on 2019/06/16. 6// Copyright © 2019 jiraffe40035. All rights reserved. 7// 8//@UIApplicationMain追加した 9import UIKit 10 @UIApplicationMain 11 12class AppDelegate:UIResponder,UIApplicationDelegate { 13 14 var window: UIWindow? 15 16 17 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 // Override point for customization after application launch. 19 return true 20 } 21 22 func applicationWillResignActive(_ application: UIApplication) { 23 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 } 26 27 func applicationDidEnterBackground(_ application: UIApplication) { 28 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 } 31 32 func applicationWillEnterForeground(_ application: UIApplication) { 33 // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 } 35 36 func applicationDidBecomeActive(_ application: UIApplication) { 37 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 } 39 40 func applicationWillTerminate(_ application: UIApplication) { 41 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42} 43 44} 45
DetailViewController2 のソースコード
//
// DetailViewController2.swift
// projects4
//
// Created by jiraffe40035 on 2019/06/17.
// Copyright © 2019 jiraffe40035. All rights reserved.
//
import UIKit
class DetailViewController2: UIViewController {
@IBOutlet weak var tappedButton: UIImageView!
override func prepare (for segue: UIStoryboardSegue,sender: Any?){
//遷移先のDetailViewController2を取得
let detavilViewController2 = segue.destination as! DetailViewController2
//タップされたボタンを要素を取得
_ = sender as! UIButton;
//ボタンタグを取得
let buttonTag = tappedButton.tag
//詳細画面に表示する画像名を生成
let detailImageName = "image" + String(buttonTag)
//詳細画面に画像名を渡す
detavilViewController2.imageName = detailImageName
}
@IBOutlet weak var detailImageView2: UIImageView!
//①追記
var imageName:String?
override func viewDidLoad() {
super.viewDidLoad()
//②更新
guard let myImageName = imageName else{
return
}
//myImageNameを用いて画像を指定
detailImageView2.image = UIImage (named:myImageName)
}
//追記
//detailImageView2.image = UIImage (named: “image7")
// Do any additional setup after loading the view.
}
/*
// 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.
}
*/
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー