質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

472閲覧

Thread 1: signal SIGABRT

burro

総合スコア12

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2020/06/14 16:47

編集2020/06/15 11:19

前提・実現したいこと

swiftで時間割アプリを作っています。アプリはstoryboardを使わずにコードで書いています。
ボタンを押すと次の画面へ遷移する部分を作っているのですがThread 1: signal SIGABRTが出ます。
遷移先のNextViewControllerにはまだ何も記述していません。
接続がうまくいっていなさっそうなのはわかるのですがswift初学者で解決法がわかりません、よろしくお願いいたします。

イメージ説明

発生している問題・エラーメッセージ

Could not cast value of type 'UIViewController' (0x10d72f750) to 'sample1_1.NextViewController' (0x106354540). 2020-06-15 01:20:15.184104+0900 sample1-1[24873:12289477] Could not cast value of type 'UIViewController' (0x10d72f750) to 'sample1_1.NextViewController' (0x106354540). (lldb)

該当のソースコード

ViewController.swift

swift

1 2import UIKit 3 4class ViewController: UIViewController { 5 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 // Do any additional setup after loading the view. 9 10 let screenWidth = self.view.bounds.width 11 let screenHeight = self.view.bounds.height//スクリーンサイズ取得 12 let testDraw = TestDraw(frame: CGRect(x :0,y:0,width:screenWidth,height:screenHeight)) 13 self.view.addSubview(testDraw) 14 15 testDraw.isOpaque = false 16 17 let label = UILabel()//タイトル時間割 18 label.frame = CGRect(x: 10,y: 100,width: screenWidth-20 ,height:30) 19 label.text = "時間割" 20 self.view.addSubview(label) 21 label.textColor = UIColor.red 22 label.textAlignment = NSTextAlignment.center 23 label.font = UIFont.systemFont(ofSize: 30) 24 25 26 let monday = UILabel() 27 monday.frame = CGRect(x:25,y:160,width: 78,height: 20) 28 monday.text = "月" 29 self.view.addSubview(monday) 30 monday.textAlignment = NSTextAlignment.center 31 32 let tuesday = UILabel() 33 tuesday.frame = CGRect(x: 103,y:160,width: 78,height: 20) 34 tuesday.text = "火" 35 self.view.addSubview(tuesday) 36 tuesday.textAlignment = NSTextAlignment.center 37 38 let wednesday = UILabel() 39 wednesday.frame = CGRect(x:181,y:160,width: 78,height: 20) 40 wednesday.text = "水" 41 self.view.addSubview(wednesday) 42 wednesday.textAlignment = NSTextAlignment.center 43 44 let thursday = UILabel() 45 thursday.frame = CGRect(x: 259,y: 160,width: 78,height:20) 46 thursday.text = "木" 47 self.view.addSubview(thursday) 48 thursday.textAlignment = NSTextAlignment.center 49 50 let friday = UILabel() 51 friday.frame = CGRect(x: 337,y: 160,width: 78,height: 20) 52 friday.text = "金" 53 self.view.addSubview(friday) 54 friday.textAlignment = NSTextAlignment.center 55 56 let cl1 = UILabel() 57 cl1.frame = CGRect(x:0,y:180,width: 25,height: 124) 58 cl1.text = "1" 59 self.view.addSubview(cl1) 60 cl1.textAlignment = NSTextAlignment.center 61 62 let cl2 = UILabel() 63 cl2.frame = CGRect(x:0,y:304,width: 25,height: 124) 64 cl2.text = "2" 65 self.view.addSubview(cl2) 66 cl2.textAlignment = NSTextAlignment.center 67 68 let cl3 = UILabel() 69 cl3.frame = CGRect(x:0,y:428,width: 25,height: 124) 70 cl3.text = "3" 71 self.view.addSubview(cl3) 72 cl3.textAlignment = NSTextAlignment.center 73 74 let cl4 = UILabel() 75 cl4.frame = CGRect(x:0,y:552,width: 25,height: 124) 76 cl4.text = "4" 77 self.view.addSubview(cl4) 78 cl4.textAlignment = NSTextAlignment.center 79 80 let cl5 = UILabel() 81 cl5.frame = CGRect(x:0,y:676,width: 25,height: 124) 82 cl5.text = "5" 83 self.view.addSubview(cl5) 84 cl5.textAlignment = NSTextAlignment.center 85 86 87 let monday1 = UIButton() 88 monday1.frame = CGRect(x:0,y:180,width: 123,height: 77) 89 monday1.setTitle("mondayclass1", for: UIControl.State.normal) 90 monday1.titleLabel?.font = UIFont.systemFont(ofSize: 3) 91 monday1.backgroundColor = UIColor.init(red: 0.9, green: 0.9, blue: 0.9, alpha: 1) 92 monday1.addTarget(self, action: #selector(monday1Button), for: .touchUpInside) 93 self.view.addSubview(monday1) 94 95 96 } 97 98 @objc func monday1Button(sender: UIButton){ 99 let storyboard : UIStoryboard = self.storyboard! 100 let nextView = storyboard.instantiateViewController(withIdentifier: "next") as! NextViewController 101 self.present(nextView, animated: true,completion: nil) 102 } 103 104 } 105

TestDraw.swift

import UIKit class TestDraw: UIView { /* // Only override draw() if you perform custom drawing. // An empty implementation adversely affects performance during animation. override func draw(_ rect: CGRect) { // Drawing code } */ override func draw(_ rect: CGRect) { let line = UIBezierPath(); //インスタンス作成 line.move(to: CGPoint(x :0,y :160));//始発点 line.addLine(to: CGPoint(x :415,y :160)) line.addLine(to: CGPoint(x :415,y:800)) line.addLine(to: CGPoint(x :0,y:800))//帰着点 line.close()//線を結ぶ UIColor.red.setStroke()//色 line.lineWidth = 1//線の太さ line.stroke()//描写 let line2 = UIBezierPath();// line2.move(to: CGPoint(x :25,y :160)) line2.addLine(to: CGPoint(x :25,y: 800)) line2.close() line2.lineWidth = 1 UIColor.red.setStroke() line2.stroke() let line3 = UIBezierPath(); line3.move(to: CGPoint(x :103,y:160)) line3.addLine(to: CGPoint(x :103,y:800)) line3.close() UIColor.red.setStroke() line3.lineWidth = 1 line3.stroke() let line4 = UIBezierPath(); line4.move(to: CGPoint(x: 181,y: 160)) line4.addLine(to: CGPoint(x: 181,y: 800)) line4.close() UIColor.red.setStroke() line4.lineWidth = 1 line4.stroke() let line5 = UIBezierPath(); line5.move(to: CGPoint(x: 259,y: 160)) line5.addLine(to: CGPoint(x: 259,y:800)) line5.close() UIColor.red.setStroke() line5.lineWidth = 1 line5.stroke() let line6 = UIBezierPath(); line6.move(to: CGPoint(x: 337,y: 160)) line6.addLine(to: CGPoint(x: 337,y:800)) line6.close() UIColor.red.setStroke() line6.lineWidth = 1 line6.stroke() let hLine1 = UIBezierPath(); hLine1.move(to: CGPoint(x:0,y:180)) hLine1.addLine(to: CGPoint(x:415,y:180)) hLine1.close() UIColor.red.setStroke() hLine1.lineWidth = 1 hLine1.stroke() let hLine2 = UIBezierPath(); hLine2.move(to: CGPoint(x:0,y:304)) hLine2.addLine(to: CGPoint(x:415,y:304)) hLine2.close() UIColor.red.setStroke() hLine2.lineWidth = 1 hLine2.stroke() let hLine3 = UIBezierPath(); hLine3.move(to: CGPoint(x:0,y:428)) hLine3.addLine(to: CGPoint(x:415,y:428)) hLine3.close() UIColor.red.setStroke() hLine3.lineWidth = 1 hLine3.stroke() let hLine4 = UIBezierPath(); hLine4.move(to: CGPoint(x: 0,y:552)) hLine4.addLine(to: CGPoint(x:415,y:552)) hLine4.close() UIColor.red.setStroke() hLine4.lineWidth = 1 hLine4.stroke() let hLine5 = UIBezierPath(); hLine5.move(to: CGPoint(x: 0,y:676)) hLine5.addLine(to: CGPoint(x: 415,y:676)) hLine5.close() UIColor.red.setStroke() hLine5.lineWidth = 1 hLine5.stroke() } }

#追記(2020.6.15)
NextViewController.swiftのコードはこのように作ってあります

import UIKit class NextViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2020/06/14 20:35

Storyboard で UIViewController のクラスを「NextViewController」と指定していると思いますが、Swift のソースコードに NextViewController が存在しない、または UIViewController のサブクラスになってないのでは。
burro

2020/06/15 11:12

初心者で申し訳ないのですが、具体的にはどう修正したら良いのでしょうか?
burro

2020/06/15 11:25

すいません!custom classのClassにNextViewControllerと入れてなくて、書いたら解決しました!ありがとうございました!
hoshi-takanori

2020/06/15 11:31

それは良かったです。????????????
guest

回答1

0

自己解決

コメント欄への解説より解決しました。ありがとうございました

投稿2020/06/20 08:31

burro

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問