前提・実現したいこと
Swift上で地図アプリを作成し,検索ボタンを押してprint文を出力する際にエラーが発生しました
エラーが発生した場所はAppdelegate.Swiftの下記に該当する部分です
class AppDelegate: UIResponder, UIApplicationDelegate {
発生している問題・エラーメッセージ
Thread 1: Exception: "-[map_app.ViewController inputText:]: unrecognized selector sent to instance 0x7ff77b004f70"
該当のソースコード
swift
1// ViewController.swift 2 3import UIKit 4import MapKit 5 6class ViewController: UIViewController, UITextFieldDelegate { 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup after loading the view. 10 inputText.delegate = self 11 } 12 13 // テキストボックス 14 @IBOutlet weak var inputText: UITextField! 15 // マップ 16 @IBOutlet weak var dispMap: MKMapView! 17 18 func textFieldShouldReturn(_ textField: UITextField) -> Bool { 19 // キーボードを閉じる 20 textField.resignFirstResponder() 21 if let searchKey = textField.text { 22 print(searchKey) 23 } 24 return true 25 } 26}
swift
1// AppDelegate.swift 2 3import UIKit 4 5@UIApplicationMain 6class AppDelegate: UIResponder, UIApplicationDelegate { 7 8 9 10 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 11 // Override point for customization after application launch. 12 return true 13 } 14 15 // MARK: UISceneSession Lifecycle 16 17 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 18 // Called when a new scene session is being created. 19 // Use this method to select a configuration to create the new scene with. 20 return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 21 } 22 23 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { 24 // Called when the user discards a scene session. 25 // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 26 // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 27 } 28 29 30}
回答1件
あなたの回答
tips
プレビュー