質問編集履歴

2

コードの追加

2021/04/26 13:59

投稿

KCROW
KCROW

スコア7

test CHANGED
File without changes
test CHANGED
@@ -262,6 +262,212 @@
262
262
 
263
263
 
264
264
 
265
+ ```SecondViewController
266
+
267
+ import UIKit
268
+
269
+
270
+
271
+ class SecondViewController: UIViewController {
272
+
273
+
274
+
275
+ @IBOutlet weak var dayLabel: UILabel!
276
+
277
+ @IBOutlet weak var syumokuText: UITextField!
278
+
279
+ @IBOutlet weak var startLabel: UITextField!
280
+
281
+ @IBOutlet weak var finishLabel: UITextField!
282
+
283
+
284
+
285
+ private var syumokupickerView = UIPickerView()
286
+
287
+ private var starttimepickerView = UIPickerView()
288
+
289
+ private var finishtimepickerView = UIPickerView()
290
+
291
+
292
+
293
+ var model = PickerModel()
294
+
295
+
296
+
297
+ override func viewDidLoad() {
298
+
299
+ super.viewDidLoad()
300
+
301
+ createPickerView()
302
+
303
+ }
304
+
305
+
306
+
307
+ @IBAction func back(_ sender: Any) {
308
+
309
+ dismiss(animated: true, completion: nil)
310
+
311
+ }
312
+
313
+
314
+
315
+ private func createPickerView() {
316
+
317
+ // syumokupickerView
318
+
319
+ syumokupickerView.delegate = self
320
+
321
+ syumokuText.inputView = syumokupickerView
322
+
323
+
324
+
325
+ // starttimepickerView
326
+
327
+ starttimepickerView.delegate = self
328
+
329
+ startLabel.inputView = starttimepickerView
330
+
331
+
332
+
333
+ // finishtimepickerView
334
+
335
+ finishtimepickerView.delegate = self
336
+
337
+ finishLabel.inputView = finishtimepickerView
338
+
339
+
340
+
341
+ }
342
+
343
+
344
+
345
+ @objc private func donePicker() {
346
+
347
+
348
+
349
+ syumokuText.endEditing(true)
350
+
351
+ startLabel.endEditing(true)
352
+
353
+ finishLabel.endEditing(true)
354
+
355
+ }
356
+
357
+
358
+
359
+ override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
360
+
361
+ syumokuText.endEditing(true)
362
+
363
+ startLabel.endEditing(true)
364
+
365
+ finishLabel.endEditing(true)
366
+
367
+ }
368
+
369
+
370
+
371
+ override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
372
+
373
+ syumokuText.endEditing(true)
374
+
375
+ startLabel.endEditing(true)
376
+
377
+ finishLabel.endEditing(true)
378
+
379
+ }
380
+
381
+
382
+
383
+ }
384
+
385
+
386
+
387
+ extension SecondViewController: UIPickerViewDelegate {
388
+
389
+
390
+
391
+ }
392
+
393
+
394
+
395
+ extension SecondViewController: UIPickerViewDataSource {
396
+
397
+
398
+
399
+ func numberOfComponents(in pickerView: UIPickerView) -> Int {
400
+
401
+ return 1
402
+
403
+ }
404
+
405
+
406
+
407
+ func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
408
+
409
+ if pickerView == syumokupickerView {
410
+
411
+ return 5
412
+
413
+ } else {
414
+
415
+ return 50
416
+
417
+ }
418
+
419
+ }
420
+
421
+ func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
422
+
423
+ if pickerView == syumokupickerView {
424
+
425
+ return model.syumokuname[row]
426
+
427
+ } else if pickerView == starttimepickerView {
428
+
429
+ return model.startimeStr[row]
430
+
431
+ } else {
432
+
433
+ return model.finishtimeStr[row]
434
+
435
+ }
436
+
437
+ }
438
+
439
+
440
+
441
+ func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
442
+
443
+ if pickerView == syumokupickerView {
444
+
445
+ syumokuText.text = model.syumokuname[row]
446
+
447
+ } else if pickerView == starttimepickerView {
448
+
449
+ startLabel.text = model.startimeStr[row]
450
+
451
+ } else {
452
+
453
+ finishLabel.text = model.finishtimeStr[row]
454
+
455
+ }
456
+
457
+ }
458
+
459
+
460
+
461
+ }
462
+
463
+
464
+
465
+ ```
466
+
467
+
468
+
469
+
470
+
265
471
  基礎的な部分で参考書を読んでいますが、つまづいています。
266
472
 
267
473
  よろしくお願いします。

1

コードの追加

2021/04/26 13:59

投稿

KCROW
KCROW

スコア7

test CHANGED
File without changes
test CHANGED
@@ -94,6 +94,172 @@
94
94
 
95
95
 
96
96
 
97
+ ```CalendarMainViewController
98
+
99
+ import UIKit
100
+
101
+ import FSCalendar
102
+
103
+
104
+
105
+ final class CalendarMainViewController: UIViewController, FSCalendarDelegate, FSCalendarDataSource, FSCalendarDelegateAppearance {
106
+
107
+
108
+
109
+ @IBOutlet private weak var calendar: FSCalendar!
110
+
111
+ @IBOutlet weak var dayLabel: UILabel!
112
+
113
+
114
+
115
+ private let CELL_NIB_NAME = "TableViewCell"
116
+
117
+ private let CELL_ID = "TableViewCell"
118
+
119
+
120
+
121
+ private var model: [PickerModel] = []
122
+
123
+
124
+
125
+
126
+
127
+ @IBOutlet private weak var tableView: UITableView! {
128
+
129
+ didSet {
130
+
131
+ let cellNIB = UINib(nibName: CELL_NIB_NAME, bundle: nil)
132
+
133
+ tableView.register(cellNIB, forCellReuseIdentifier: CELL_ID)
134
+
135
+
136
+
137
+ tableView.delegate = self
138
+
139
+ tableView.dataSource = self
140
+
141
+
142
+
143
+ }
144
+
145
+ }
146
+
147
+
148
+
149
+ func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
150
+
151
+ let formattar = DateFormatter()
152
+
153
+ formattar.dateFormat = "yyyy年MM月dd日"
154
+
155
+ let selectedDate = formattar.string(from: date)
156
+
157
+ print(selectedDate)
158
+
159
+ dayLabel.text = selectedDate
160
+
161
+ }
162
+
163
+
164
+
165
+ override func viewDidLoad() {
166
+
167
+ super.viewDidLoad()
168
+
169
+
170
+
171
+ self.calendar.dataSource = self
172
+
173
+ self.calendar.delegate = self
174
+
175
+
176
+
177
+ let myDate = Date()
178
+
179
+ let tempCalendar = Calendar.current
180
+
181
+ let nowYear = tempCalendar.component(.year, from: myDate)
182
+
183
+ let nowMonth = tempCalendar.component(.month, from: myDate)
184
+
185
+ let nowDay = tempCalendar.component(.day, from: myDate)
186
+
187
+ let calendar = Calendar.current
188
+
189
+ _ = calendar.date(from: DateComponents(year: nowYear, month: nowMonth, day: nowDay))
190
+
191
+
192
+
193
+ }
194
+
195
+
196
+
197
+ }
198
+
199
+
200
+
201
+ extension CalendarMainViewController: UITableViewDataSource {
202
+
203
+
204
+
205
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
206
+
207
+ return model.count
208
+
209
+
210
+
211
+ }
212
+
213
+
214
+
215
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
216
+
217
+ guard let cell = tableView.dequeueReusableCell(withIdentifier: CELL_ID, for: indexPath) as? TableViewCell else {
218
+
219
+ return UITableViewCell()
220
+
221
+ }
222
+
223
+ let user = model[indexPath.row]
224
+
225
+ cell.configure(menu: user)
226
+
227
+ return cell
228
+
229
+ }
230
+
231
+
232
+
233
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
234
+
235
+ return 150
236
+
237
+ }
238
+
239
+
240
+
241
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
242
+
243
+ tableView.deselectRow(at: indexPath as IndexPath, animated: true)
244
+
245
+
246
+
247
+ }
248
+
249
+
250
+
251
+ }
252
+
253
+ extension CalendarMainViewController: UITableViewDelegate {
254
+
255
+
256
+
257
+ }
258
+
259
+
260
+
261
+ ```
262
+
97
263
 
98
264
 
99
265
  基礎的な部分で参考書を読んでいますが、つまづいています。