質問編集履歴

5

修正

2016/12/26 03:10

投稿

minoossp
minoossp

スコア42

test CHANGED
File without changes
test CHANGED
@@ -430,7 +430,9 @@
430
430
 
431
431
 
432
432
 
433
-
433
+ ![イメージ説明](e637b7703672b8dc48dcf1e020b29001.png)
434
+
435
+ ここでエラーになります
434
436
 
435
437
 
436
438
 

4

修正

2016/12/26 03:10

投稿

minoossp
minoossp

スコア42

test CHANGED
File without changes
test CHANGED
@@ -400,7 +400,7 @@
400
400
 
401
401
  //
402
402
 
403
- if tableView.tag == 0 {
403
+
404
404
 
405
405
  cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
406
406
 
@@ -408,19 +408,7 @@
408
408
 
409
409
 
410
410
 
411
- } else if tableView.tag == 1 {
411
+
412
-
413
-
414
-
415
- cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
416
-
417
- cell.Label2.text = raberuni[tableView.tag][indexPath.row]
418
-
419
-
420
-
421
-
422
-
423
- }
424
412
 
425
413
 
426
414
 

3

修正

2016/12/26 03:02

投稿

minoossp
minoossp

スコア42

test CHANGED
File without changes
test CHANGED
@@ -392,6 +392,12 @@
392
392
 
393
393
  //
394
394
 
395
+ print("tableView.tag: \(tableView.tag)")
396
+
397
+ print("indexPath.row: \(indexPath.row)")
398
+
399
+
400
+
395
401
  //
396
402
 
397
403
  if tableView.tag == 0 {
@@ -418,7 +424,7 @@
418
424
 
419
425
 
420
426
 
421
- print("tableView.tag: \(tableView.tag)")
427
+
422
428
 
423
429
 
424
430
 

2

追加

2016/12/26 02:27

投稿

minoossp
minoossp

スコア42

test CHANGED
File without changes
test CHANGED
@@ -394,31 +394,29 @@
394
394
 
395
395
  //
396
396
 
397
- if tableView.tag == 1 {
397
+ if tableView.tag == 0 {
398
-
398
+
399
- cell.Label1.text = raberuiti[0][indexPath.row]
399
+ cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
400
-
400
+
401
- cell.Label2.text = raberuni[0][indexPath.row]
401
+ cell.Label2.text = raberuni[tableView.tag][indexPath.row]
402
-
403
-
404
-
405
- // cell.textLabel?.text = "\(myItems[0][indexPath.row])"
402
+
406
-
403
+
404
+
407
- } else if tableView.tag == 2 {
405
+ } else if tableView.tag == 1 {
408
-
409
-
410
-
406
+
407
+
408
+
411
- cell.Label1.text = raberuiti[1][indexPath.row]
409
+ cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
412
-
410
+
413
- cell.Label2.text = raberuni[1][indexPath.row]
411
+ cell.Label2.text = raberuni[tableView.tag][indexPath.row]
414
-
415
-
416
-
417
- // cell.textLabel?.text = "\(myItems[1][indexPath.row])"
412
+
418
-
413
+
414
+
415
+
416
+
419
- }
417
+ }
420
-
421
- //
418
+
419
+
422
420
 
423
421
  print("tableView.tag: \(tableView.tag)")
424
422
 

1

追加

2016/12/26 02:10

投稿

minoossp
minoossp

スコア42

test CHANGED
File without changes
test CHANGED
@@ -174,7 +174,267 @@
174
174
 
175
175
 
176
176
 
177
-
177
+ ```
178
+
179
+
180
+
181
+ import UIKit
182
+
183
+
184
+
185
+ class ViewController: UIViewController, UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource {
186
+
187
+
188
+
189
+ // UIScrollView.
190
+
191
+ var scrollView: UIScrollView!
192
+
193
+ // TableViewのアイテム.
194
+
195
+
196
+
197
+ let raberuiti: [[String]] = [["ご飯", "味噌汁", "焼き魚"],["天津飯", "チャーハン", "八宝菜", "酢豚", "肉まん"]]
198
+
199
+
200
+
201
+ let raberuni: [[String]] = [["1980/2/27", "1983/8/25", "2016/10/10"],["2016/6/24", "2014/12/16", "2014/8/16", "2014/11/16", "2018/12/3"]]
202
+
203
+
204
+
205
+
206
+
207
+ // TableView.
208
+
209
+ var myTableView: [UITableView] = []
210
+
211
+ // ページ番号.
212
+
213
+ let pageSize = 2
214
+
215
+
216
+
217
+ override func viewDidLoad() {
218
+
219
+ super.viewDidLoad()
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+ // ScrollViewの設定.
228
+
229
+ let width = self.view.frame.maxX
230
+
231
+ scrollView = UIScrollView(frame: self.view.frame)
232
+
233
+ scrollView.showsHorizontalScrollIndicator = false;
234
+
235
+ scrollView.showsVerticalScrollIndicator = false
236
+
237
+ scrollView.isPagingEnabled = true
238
+
239
+ scrollView.delegate = self
240
+
241
+ scrollView.contentSize = CGSize(width:CGFloat(pageSize) * width, height:0)
242
+
243
+ self.view.addSubview(scrollView)
244
+
245
+
246
+
247
+ // Status Barの高さを取得.
248
+
249
+ let barHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height
250
+
251
+
252
+
253
+ // Viewの高さと幅を取得.
254
+
255
+ let displayWidth: CGFloat = self.view.frame.width
256
+
257
+ let displayHeight: CGFloat = self.view.frame.height
258
+
259
+
260
+
261
+
262
+
263
+ for i in 0 ..< pageSize {
264
+
265
+
266
+
267
+ let tableView: UITableView = UITableView(frame: CGRect(x: CGFloat(i) * width, y: barHeight, width: displayWidth, height: displayHeight - barHeight))
268
+
269
+ tableView.estimatedRowHeight = 60
270
+
271
+ tableView.rowHeight = UITableViewAutomaticDimension
272
+
273
+ tableView.tag = i
274
+
275
+ tableView.dataSource = self
276
+
277
+ tableView.delegate = self
278
+
279
+ tableView.register(TableViewCell.self, forCellReuseIdentifier: "MyCell")
280
+
281
+ myTableView.append(tableView)
282
+
283
+
284
+
285
+ scrollView.addSubview(myTableView[i])
286
+
287
+
288
+
289
+
290
+
291
+ }
292
+
293
+
294
+
295
+ print("myTableView[]: \(myTableView)")
296
+
297
+
298
+
299
+
300
+
301
+ }
302
+
303
+
304
+
305
+ func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
306
+
307
+
308
+
309
+ // スクロール数が1ページ分になったら.
310
+
311
+ if fmod(scrollView.contentOffset.x, scrollView.frame.maxX) == 0 {
312
+
313
+ // ページの場所を切り替える.
314
+
315
+ // pageControl.currentPage = Int(scrollView.contentOffset.x / scrollView.frame.maxX)
316
+
317
+ }
318
+
319
+ }
320
+
321
+
322
+
323
+ /*
324
+
325
+ Cellが選択された際に呼び出される.
326
+
327
+ */
328
+
329
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
330
+
331
+ if tableView.tag == 0 {
332
+
333
+ print("Num: \(indexPath.row)")
334
+
335
+ } else if tableView.tag == 1 {
336
+
337
+ print("Num: \(indexPath.row)")
338
+
339
+ }
340
+
341
+
342
+
343
+ }
344
+
345
+
346
+
347
+ /*
348
+
349
+ Cellの総数を返す.
350
+
351
+ */
352
+
353
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
354
+
355
+ if tableView.tag == 0 {
356
+
357
+ return raberuiti[0].count
358
+
359
+ } else if tableView.tag == 1 {
360
+
361
+ return raberuiti[1].count
362
+
363
+ } else{
364
+
365
+ return 0
366
+
367
+ }
368
+
369
+
370
+
371
+ }
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+ /*
380
+
381
+ Cellに値を設定する.
382
+
383
+ */
384
+
385
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
386
+
387
+ //
388
+
389
+ let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! TableViewCell
390
+
391
+ //
392
+
393
+ //
394
+
395
+ //
396
+
397
+ if tableView.tag == 1 {
398
+
399
+ cell.Label1.text = raberuiti[0][indexPath.row]
400
+
401
+ cell.Label2.text = raberuni[0][indexPath.row]
402
+
403
+
404
+
405
+ // cell.textLabel?.text = "\(myItems[0][indexPath.row])"
406
+
407
+ } else if tableView.tag == 2 {
408
+
409
+
410
+
411
+ cell.Label1.text = raberuiti[1][indexPath.row]
412
+
413
+ cell.Label2.text = raberuni[1][indexPath.row]
414
+
415
+
416
+
417
+ // cell.textLabel?.text = "\(myItems[1][indexPath.row])"
418
+
419
+ }
420
+
421
+ //
422
+
423
+ print("tableView.tag: \(tableView.tag)")
424
+
425
+
426
+
427
+
428
+
429
+ return cell
430
+
431
+ }
432
+
433
+
434
+
435
+ }
436
+
437
+ ```
178
438
 
179
439
 
180
440