質問するログイン新規登録

質問編集履歴

5

修正

2016/12/26 03:10

投稿

minoossp
minoossp

スコア42

title CHANGED
File without changes
body CHANGED
@@ -214,6 +214,7 @@
214
214
  }
215
215
  ```
216
216
 
217
+ ![イメージ説明](e637b7703672b8dc48dcf1e020b29001.png)
218
+ ここでエラーになります
217
219
 
218
-
219
220
  swift3.0 xcode8.3

4

修正

2016/12/26 03:10

投稿

minoossp
minoossp

スコア42

title CHANGED
File without changes
body CHANGED
@@ -199,17 +199,11 @@
199
199
  print("indexPath.row: \(indexPath.row)")
200
200
 
201
201
  //
202
- if tableView.tag == 0 {
202
+
203
203
  cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
204
204
  cell.Label2.text = raberuni[tableView.tag][indexPath.row]
205
205
 
206
- } else if tableView.tag == 1 {
206
+
207
-
208
- cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
209
- cell.Label2.text = raberuni[tableView.tag][indexPath.row]
210
-
211
-
212
- }
213
207
 
214
208
 
215
209
 

3

修正

2016/12/26 03:02

投稿

minoossp
minoossp

スコア42

title CHANGED
File without changes
body CHANGED
@@ -195,6 +195,9 @@
195
195
  let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! TableViewCell
196
196
  //
197
197
  //
198
+ print("tableView.tag: \(tableView.tag)")
199
+ print("indexPath.row: \(indexPath.row)")
200
+
198
201
  //
199
202
  if tableView.tag == 0 {
200
203
  cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
@@ -208,9 +211,9 @@
208
211
 
209
212
  }
210
213
 
211
- print("tableView.tag: \(tableView.tag)")
212
214
 
213
215
 
216
+
214
217
  return cell
215
218
  }
216
219
 

2

追加

2016/12/26 02:27

投稿

minoossp
minoossp

スコア42

title CHANGED
File without changes
body CHANGED
@@ -196,19 +196,18 @@
196
196
  //
197
197
  //
198
198
  //
199
- if tableView.tag == 1 {
199
+ if tableView.tag == 0 {
200
- cell.Label1.text = raberuiti[0][indexPath.row]
200
+ cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
201
- cell.Label2.text = raberuni[0][indexPath.row]
201
+ cell.Label2.text = raberuni[tableView.tag][indexPath.row]
202
202
 
203
- // cell.textLabel?.text = "\(myItems[0][indexPath.row])"
204
- } else if tableView.tag == 2 {
203
+ } else if tableView.tag == 1 {
205
204
 
206
- cell.Label1.text = raberuiti[1][indexPath.row]
205
+ cell.Label1.text = raberuiti[tableView.tag][indexPath.row]
207
- cell.Label2.text = raberuni[1][indexPath.row]
206
+ cell.Label2.text = raberuni[tableView.tag][indexPath.row]
208
207
 
209
- // cell.textLabel?.text = "\(myItems[1][indexPath.row])"
208
+
210
209
  }
211
- //
210
+
212
211
  print("tableView.tag: \(tableView.tag)")
213
212
 
214
213
 

1

追加

2016/12/26 02:10

投稿

minoossp
minoossp

スコア42

title CHANGED
File without changes
body CHANGED
@@ -86,8 +86,138 @@
86
86
 
87
87
  ###補足情報(言語/FW/ツール等のバージョンなど)
88
88
 
89
+ ```
89
90
 
91
+ import UIKit
90
92
 
93
+ class ViewController: UIViewController, UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource {
94
+
95
+ // UIScrollView.
96
+ var scrollView: UIScrollView!
97
+ // TableViewのアイテム.
98
+
99
+ let raberuiti: [[String]] = [["ご飯", "味噌汁", "焼き魚"],["天津飯", "チャーハン", "八宝菜", "酢豚", "肉まん"]]
100
+
101
+ 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"]]
91
102
 
92
103
 
104
+ // TableView.
105
+ var myTableView: [UITableView] = []
106
+ // ページ番号.
107
+ let pageSize = 2
108
+
109
+ override func viewDidLoad() {
110
+ super.viewDidLoad()
111
+
112
+
113
+
114
+ // ScrollViewの設定.
115
+ let width = self.view.frame.maxX
116
+ scrollView = UIScrollView(frame: self.view.frame)
117
+ scrollView.showsHorizontalScrollIndicator = false;
118
+ scrollView.showsVerticalScrollIndicator = false
119
+ scrollView.isPagingEnabled = true
120
+ scrollView.delegate = self
121
+ scrollView.contentSize = CGSize(width:CGFloat(pageSize) * width, height:0)
122
+ self.view.addSubview(scrollView)
123
+
124
+ // Status Barの高さを取得.
125
+ let barHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height
126
+
127
+ // Viewの高さと幅を取得.
128
+ let displayWidth: CGFloat = self.view.frame.width
129
+ let displayHeight: CGFloat = self.view.frame.height
130
+
131
+
132
+ for i in 0 ..< pageSize {
133
+
134
+ let tableView: UITableView = UITableView(frame: CGRect(x: CGFloat(i) * width, y: barHeight, width: displayWidth, height: displayHeight - barHeight))
135
+ tableView.estimatedRowHeight = 60
136
+ tableView.rowHeight = UITableViewAutomaticDimension
137
+ tableView.tag = i
138
+ tableView.dataSource = self
139
+ tableView.delegate = self
140
+ tableView.register(TableViewCell.self, forCellReuseIdentifier: "MyCell")
141
+ myTableView.append(tableView)
142
+
143
+ scrollView.addSubview(myTableView[i])
144
+
145
+
146
+ }
147
+
148
+ print("myTableView[]: \(myTableView)")
149
+
150
+
151
+ }
152
+
153
+ func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
154
+
155
+ // スクロール数が1ページ分になったら.
156
+ if fmod(scrollView.contentOffset.x, scrollView.frame.maxX) == 0 {
157
+ // ページの場所を切り替える.
158
+ // pageControl.currentPage = Int(scrollView.contentOffset.x / scrollView.frame.maxX)
159
+ }
160
+ }
161
+
162
+ /*
163
+ Cellが選択された際に呼び出される.
164
+ */
165
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
166
+ if tableView.tag == 0 {
167
+ print("Num: \(indexPath.row)")
168
+ } else if tableView.tag == 1 {
169
+ print("Num: \(indexPath.row)")
170
+ }
171
+
172
+ }
173
+
174
+ /*
175
+ Cellの総数を返す.
176
+ */
177
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
178
+ if tableView.tag == 0 {
179
+ return raberuiti[0].count
180
+ } else if tableView.tag == 1 {
181
+ return raberuiti[1].count
182
+ } else{
183
+ return 0
184
+ }
185
+
186
+ }
187
+
188
+
189
+
190
+ /*
191
+ Cellに値を設定する.
192
+ */
193
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
194
+ //
195
+ let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! TableViewCell
196
+ //
197
+ //
198
+ //
199
+ if tableView.tag == 1 {
200
+ cell.Label1.text = raberuiti[0][indexPath.row]
201
+ cell.Label2.text = raberuni[0][indexPath.row]
202
+
203
+ // cell.textLabel?.text = "\(myItems[0][indexPath.row])"
204
+ } else if tableView.tag == 2 {
205
+
206
+ cell.Label1.text = raberuiti[1][indexPath.row]
207
+ cell.Label2.text = raberuni[1][indexPath.row]
208
+
209
+ // cell.textLabel?.text = "\(myItems[1][indexPath.row])"
210
+ }
211
+ //
212
+ print("tableView.tag: \(tableView.tag)")
213
+
214
+
215
+ return cell
216
+ }
217
+
218
+ }
219
+ ```
220
+
221
+
222
+
93
223
  swift3.0 xcode8.3