質問編集履歴

4

現在の状況記載

2017/06/29 02:03

投稿

Honma
Honma

スコア25

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,66 @@
1
- **2017/6/28 16:00 すいません質問内容大幅に変更しました**
1
+ 現在の状況(2017/6/29 11:00)
2
+
2
-
3
+ ---
4
+
3
-
5
+ ```ここに言語を入力
6
+
4
-
7
+ required init?(coder aDecoder: NSCoder) {
8
+
5
-
9
+ // super.init(coder: aDecoder)
10
+
11
+ super.init(text: self.text, fontsize: CGFloat!, posX: CGFloat!, posY: CGFloat!, addView: SKScene!,
12
+
13
+ nextLineKey: Character!, maxWidth: UInt!, delayTime: CGFloat!, mode: eTextState!, color: UIColor!){
14
+
15
+ super.init(frame: .zero)
16
+
17
+
18
+
19
+ if (nextLineKey != nil) { m_nextLineKey = nextLineKey }
20
+
21
+ if (maxWidth != nil) { self.maxWidth = maxWidth }
22
+
23
+ if (delayTime != nil) { self.m_delayTime = delayTime }
24
+
25
+ if (mode != nil) { self.m_state = mode }
26
+
27
+ if (fontsize != nil) { self.m_fontSize = fontsize }
28
+
29
+ if (color != nil) { self.m_color = color }
30
+
31
+
32
+
33
+
34
+
35
+ self.m_posX = posX
36
+
37
+ self.m_posY = posY
38
+
39
+ self.m_parentScene = addView
40
+
41
+
42
+
43
+ drawText(text: text)
44
+
45
+ }
46
+
47
+ }
48
+
49
+ ```
50
+
51
+ 目的:
52
+
53
+ init(coder:)の中から必要なイニシャライザを呼びたい
54
+
55
+ 状況:
56
+
57
+ super.initの引数部分でCannot invoke '〜' with an argument list of type '〜'がでる
58
+
59
+ 引数に問題があるようなのだが、解決できない
60
+
61
+
62
+
63
+ ---
6
64
 
7
65
  スマートフォン向けアプリ開発を下記の環境で行っています。
8
66
 
@@ -14,76 +72,14 @@
14
72
 
15
73
  http://neight968.hatenablog.com/entry/2015/07/22/040538
16
74
 
17
- 上記URLのソースコードをクラス化しLabelに実装したいのですが、
75
+ 上記URLのソースコードをクラス化しLabelに実装したい
18
-
19
- ビルド時にTextEsCapement1.swift内
76
+
20
-
21
- drawText(text: text)
77
+
22
-
78
+
23
- という箇所で
79
+ ソース
24
-
25
- Use of "self" in method call 'drawtext' before super.init initializes self
26
-
27
- というのと、
28
-
29
- その直後の閉じ括弧で、
30
-
31
- Super.init isn't called on all paths before returning from initializer
32
-
33
- という2種類のビルドエラーが出ます。
34
-
35
- エラー解消のために調べたこと。試したこと
36
80
 
37
81
  ---
38
82
 
39
- まず、
40
-
41
- Use of "self" in method call 'drawtext' before super.init initializes self
42
-
43
- は、「super.initを呼ぶ前に'drawtext'にアクセスするのにselfを使っている」
44
-
45
- という意味のエラーのようでしたので、
46
-
47
- drawTextが含まれるinit関数の一番最初に
48
-
49
- super.init()
50
-
51
- を追加したのですが、次は
52
-
53
- Must call a designated initializer of the superclass 'UILabel'
54
-
55
- (スーパークラス 'UILabel'の指定された初期化子を呼び出さなければなりません)
56
-
57
- というエラーに変化し、ここで行き詰ってしまいました。
58
-
59
-
60
-
61
- 次に,
62
-
63
- Super.init isn't called on all paths before returning from initializer
64
-
65
- (初期化メソッドから戻る(メソッドが終了する)時点より前に、どんな経路でもsuper.initが呼ばれていません)
66
-
67
- ですが、これについては1個目のエラーが解決すれば同時に解消されるのでは、と判断し、保留にしている状況です。
68
-
69
-
70
-
71
- 実装のためにやったこと
72
-
73
- ---
74
-
75
- ①上記URLのソースを、swiftファイル新規作成で作ったTextEsCapement1.swiftにそのまま貼り付け
76
-
77
- ②記法が古かったところを、xcodeの警告に従い修正
78
-
79
- ③ストーリーボード上にてLabelのclassにTextEsCapement1を設定
80
-
81
-
82
-
83
- ソース
84
-
85
- ---
86
-
87
83
  このほかに必要であれば追加します
88
84
 
89
85
 

3

試したことの記載追加

2017/06/29 02:03

投稿

Honma
Honma

スコア25

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,39 @@
32
32
 
33
33
  という2種類のビルドエラーが出ます。
34
34
 
35
-
35
+ エラー解消のために調べたこと。試したこと
36
+
37
+ ---
38
+
39
+ まず、
40
+
41
+ Use of "self" in method call 'drawtext' before super.init initializes self
42
+
43
+ は、「super.initを呼ぶ前に'drawtext'にアクセスするのにselfを使っている」
44
+
45
+ という意味のエラーのようでしたので、
46
+
47
+ drawTextが含まれるinit関数の一番最初に
48
+
49
+ super.init()
50
+
51
+ を追加したのですが、次は
52
+
53
+ Must call a designated initializer of the superclass 'UILabel'
54
+
55
+ (スーパークラス 'UILabel'の指定された初期化子を呼び出さなければなりません)
56
+
57
+ というエラーに変化し、ここで行き詰ってしまいました。
58
+
59
+
60
+
61
+ 次に,
62
+
63
+ Super.init isn't called on all paths before returning from initializer
64
+
65
+ (初期化メソッドから戻る(メソッドが終了する)時点より前に、どんな経路でもsuper.initが呼ばれていません)
66
+
67
+ ですが、これについては1個目のエラーが解決すれば同時に解消されるのでは、と判断し、保留にしている状況です。
36
68
 
37
69
 
38
70
 

2

微修正

2017/06/28 08:05

投稿

Honma
Honma

スコア25

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,9 @@
24
24
 
25
25
  Use of "self" in method call 'drawtext' before super.init initializes self
26
26
 
27
- というのと
27
+ というのと
28
+
29
+ その直後の閉じ括弧で、
28
30
 
29
31
  Super.init isn't called on all paths before returning from initializer
30
32
 

1

質問内容変更

2017/06/28 07:35

投稿

Honma
Honma

スコア25

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,9 @@
1
+ **2017/6/28 16:00 すいません質問内容大幅に変更しました**
2
+
3
+
4
+
5
+
6
+
1
7
  スマートフォン向けアプリ開発を下記の環境で行っています。
2
8
 
3
9
  Swift3.0.1
@@ -10,13 +16,19 @@
10
16
 
11
17
  上記URLのソースコードをクラス化しLabelに実装したいのですが、
12
18
 
13
-
14
-
15
- ![イメージ説明](1f6f785eae859c2c5d59fbe4b839a6be.png)
19
+ ビルド時にTextEsCapement1.swift内
20
+
16
-
21
+ drawText(text: text)
22
+
17
-
23
+ という箇所で
24
+
18
-
25
+ Use of "self" in method call 'drawtext' before super.init initializes self
26
+
27
+ というのと
28
+
19
- 実行して該当Viewに遷移時に上記の画像のようなエラーが出ます。(SmartRiceGrowingはプロジェクト名)
29
+ Super.init isn't called on all paths before returning from initializer
30
+
31
+ という2種類のビルドエラーが出ます。
20
32
 
21
33
 
22
34
 
@@ -30,24 +42,14 @@
30
42
 
31
43
  ②記法が古かったところを、xcodeの警告に従い修正
32
44
 
33
- ③全体図にもある通り、customsegueを使っているため、その都合上TextEsCapement1.swiftにNSObjectの継承を追加
34
-
35
- ④警告が出ていたのでdrawText(text: text)の前に、super.init()を追加
36
-
37
- ストーリーボード上にてLabelのclassにTextEsCapement1を設定
45
+ ストーリーボード上にてLabelのclassにTextEsCapement1を設定
38
-
46
+
47
+
48
+
39
- 全体図
49
+ ソース
40
50
 
41
51
  ---
42
52
 
43
- ![イメージ説明](1c33ba323fc11f266f722a80caf62bdc.png)
44
-
45
- 各ソース
46
-
47
- ---
48
-
49
- とりあえず関係ありそうなものを
50
-
51
53
  このほかに必要であれば追加します
52
54
 
53
55
 
@@ -74,7 +76,7 @@
74
76
 
75
77
 
76
78
 
77
- class TextEscapement1 : NSObject {
79
+ class TextEscapement1 : UILabel{
78
80
 
79
81
 
80
82
 
@@ -226,9 +228,15 @@
226
228
 
227
229
 
228
230
 
229
- super.init()
230
-
231
- drawText(text: text)
231
+ drawText(text: text) // **ここでエラーが発生**
232
+
233
+ }
234
+
235
+
236
+
237
+ required init? (coder aDecoder: NSCoder) {
238
+
239
+ fatalError("init(coder: has not been implemented)")
232
240
 
233
241
  }
234
242
 
@@ -497,75 +505,3 @@
497
505
  }
498
506
 
499
507
  ```
500
-
501
- **CustomSegue.swift**
502
-
503
- ```ここに言語を入力
504
-
505
- import UIKit
506
-
507
-
508
-
509
- class CustomSegue: UIStoryboardSegue {
510
-
511
- override func perform() {
512
-
513
- //遷移前のViewControllerのインスタンスを作成
514
-
515
- let firstVCView = self.source.view as UIView!
516
-
517
- //遷移後のViewControllerのインスタンスを作成
518
-
519
- let secondVCView = self.destination.view as UIView!
520
-
521
-
522
-
523
- //画面の横の長さを取得
524
-
525
- let screenWidth = UIScreen.main.bounds.size.width
526
-
527
- //画面の縦の長さを取得
528
-
529
- let screenHeight = UIScreen.main.bounds.size.height
530
-
531
-
532
-
533
- //遷移後のビューを画面の外(右側)にだしておく
534
-
535
- secondVCView?.frame = CGRect(x:screenWidth, y:0.0, width:screenWidth, height:screenHeight)
536
-
537
-
538
-
539
- let window = UIApplication.shared.keyWindow
540
-
541
- window?.insertSubview(secondVCView!, aboveSubview: firstVCView!)
542
-
543
-
544
-
545
- //0.4秒で遷移する
546
-
547
- UIView.animate(withDuration: 0.4, animations: { () -> Void in
548
-
549
- //遷移前のビューを現在の位置から画面幅分移動する
550
-
551
- firstVCView?.frame = ((firstVCView?.frame)?.offsetBy(dx: -screenWidth, dy: 0.0))!
552
-
553
- //遷移後のビューを現在の位置(画面外)から画面幅分移動する
554
-
555
- secondVCView?.frame = (secondVCView?.frame.offsetBy(dx: -screenWidth, dy: 0.0))!
556
-
557
- }) { (Finished) -> Void in
558
-
559
- self.source.present(self.destination as UIViewController,
560
-
561
- animated: false,
562
-
563
- completion: nil)
564
-
565
- }
566
-
567
- }
568
-
569
- }
570
-
571
- ```