質問編集履歴

3

追加

2019/08/27 07:44

投稿

ROKIDOG
ROKIDOG

スコア20

test CHANGED
File without changes
test CHANGED
@@ -68,7 +68,7 @@
68
68
 
69
69
  //ここでThread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional valueのエラー
70
70
 
71
- musicPostViewControllrt.questionPostLabel = questionLabel.text as! String
71
+ musicPostViewControllrt.questionPostLabel.text = questionLabel.text as! String
72
72
 
73
73
  }
74
74
 
@@ -79,3 +79,129 @@
79
79
  }
80
80
 
81
81
  ```
82
+
83
+ 解決
84
+
85
+ 遷移先(MusicPostViewController)のviewdidloadにquestionPostLabel.text = questionlabelと表示しnilが入らないようにして、そのquestionlabelに遷移元で表示したquestionable(=questionLabel.text)を代入することで成功しました!
86
+
87
+ 回答者の皆様本当にありがとうございました!!
88
+
89
+
90
+
91
+ 遷移元
92
+
93
+ ```ここに言語を入力
94
+
95
+ class MusicViewController: UIViewController ,IndicatorInfoProvider {
96
+
97
+
98
+
99
+ //ここがボタンのタイトルに利用されます
100
+
101
+ var itemInfo: IndicatorInfo = "音楽"
102
+
103
+ var questionlabel:String?
104
+
105
+ @IBOutlet weak var questionLabel: UILabel!
106
+
107
+ @IBOutlet weak var label: UILabel!
108
+
109
+ override func viewDidLoad() {
110
+
111
+ super.viewDidLoad()
112
+
113
+ questionLabel.text = "オススメの曲は?"
114
+
115
+ }
116
+
117
+
118
+
119
+ //必須
120
+
121
+ func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
122
+
123
+ return itemInfo
124
+
125
+ }
126
+
127
+ @IBAction func toMusicpost() {
128
+
129
+      //questionlabelにquestionLabel.text代入
130
+
131
+ questionlabel = questionLabel.text
132
+
133
+ performSegue(withIdentifier: "toMusicPost", sender: nil)
134
+
135
+
136
+
137
+ }
138
+
139
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
140
+
141
+ if segue.identifier == "toMusicPost"{
142
+
143
+ let musicPostViewControllr = segue.destination as! MusicPostViewController
144
+
145
+
146
+
147
+ musicPostViewControllr.questionlabel = questionlabel
148
+
149
+ }
150
+
151
+
152
+
153
+ }
154
+
155
+ }
156
+
157
+ ```
158
+
159
+ 遷移先
160
+
161
+ ```ここに言語を入力
162
+
163
+ class MusicPostViewController: UIViewController,UINavigationControllerDelegate, UIImagePickerControllerDelegate, UITextViewDelegate {
164
+
165
+
166
+
167
+ let placeholderImage = UIImage(named: "photo-placeholder")
168
+
169
+ let musicViewController = MusicViewController()
170
+
171
+
172
+
173
+ var resizedImage: UIImage!
174
+
175
+   //questionlabe保持
176
+
177
+ var questionlabel:String?
178
+
179
+ @IBOutlet weak var questionPostLabel: UILabel!
180
+
181
+ @IBOutlet var postImageView: UIImageView!
182
+
183
+
184
+
185
+ @IBOutlet var postTextView: UITextView!
186
+
187
+
188
+
189
+ @IBOutlet var postButton: UIBarButtonItem!
190
+
191
+
192
+
193
+ override func viewDidLoad() {
194
+
195
+ super.viewDidLoad()
196
+
197
+ postTextView.delegate = self
198
+
199
+      //初期値にquestionlabelが入る
200
+
201
+ questionPostLabel.text = questionlabel
202
+
203
+
204
+
205
+ }
206
+
207
+ ```

2

編集

2019/08/27 07:44

投稿

ROKIDOG
ROKIDOG

スコア20

test CHANGED
File without changes
test CHANGED
@@ -54,7 +54,7 @@
54
54
 
55
55
 
56
56
 
57
- performSegue(withIdentifier: "toPost", sender: nil)
57
+ performSegue(withIdentifier: "toMusicPost", sender: nil)
58
58
 
59
59
 
60
60
 

1

編集

2019/08/27 03:59

投稿

ROKIDOG
ROKIDOG

スコア20

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,15 @@
4
4
 
5
5
 
6
6
 
7
+ segueで渡そうと思い@IBAction func toMusicpost()で以下のように書いたのですが、Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional valueというエラーが出てしまいます。
8
+
9
+ これは予期せぬエラーが見つかったということなのでas! Stringと書いてみましたが変化なしでした。。
10
+
11
+ 接続されていることも確認しましたが、どういった対処が必要でしょうか。
12
+
13
+
14
+
7
- segue
15
+ 何かヒント頂けると幸いす。
8
16
 
9
17
 
10
18
 
@@ -58,9 +66,9 @@
58
66
 
59
67
  let musicPostViewControllrt = segue.destination as! MusicPostViewController
60
68
 
61
-
69
+ //ここでThread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional valueのエラー
62
70
 
63
- musicPostViewControllrt.questionPostLabel = questionLabel.text as! UILabel
71
+ musicPostViewControllrt.questionPostLabel = questionLabel.text as! String
64
72
 
65
73
  }
66
74