全体のコードを示しておらず申し訳ありません.アドバイスいただいた方々ありがとうございました。
appendはされていたのですが、これをtableVIewに表示させる際に再読み込みができておりませんでした.
swift
1
2
3import UIKit
4let sectionTitle = ["情報系","心理系","食物系"]
5
6struct Setdata{
7 var name: String
8 var url: String
9}
10
11// セルに表示するデータ
12//var section0:[(String,String)] = []
13var section0 = [
14 (name:"アップル", url:"https://www.apple.com/jp/"),
15 (name:"国立天文台", url:"https://www.nao.ac.jp"),
16 (name:"東京都美術館", url:"http://www.tobikan.jp"),
17 (name:"amazon", url:"https://www.amazon.co.jp")
18]
19var section1 = [
20 (name:"本", url:"https://docs.google.com/forms/d/1z9r11-QxxvSV96fvThVZQjGmpFaEvqim7Lt2pGcPUZA/edit#responses")]
21
22var section2 = [
23 (name:"o-tips", url:"https://docs.google.com/forms/d/1qfWWtPXuKnJHg1XWiu3qX9pHXx1BsE-LL--MR57p0Jk/edit")]
24
25var tableData = [section0,section1,section2]
26
27
28
29
30class WebListTableTableViewController: UITableViewController {
31
32 var path : String = ""
33 var Point : Int = 0
34
35
36 //var me : AppUser(data : ["UserPoint" : 0])
37 //var me = AppUser (data : ["UserPoint" : 1])
38
39 let me = AppUser()
40
41 // MARK: - Table view data source
42
43 // セクションの個数
44 override func numberOfSections(in tableView: UITableView) -> Int {
45 return sectionTitle.count
46 }
47
48 // セクション内の行数
49 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
50 let sectionData = tableData[section]
51 return sectionData.count
52 // 配列webListの値の個数
53 //return webList.count
54 }
55
56 override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
57 return sectionTitle[section]
58 }
59
60 // セルを作る
61 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
62 // テーブルのセルを参照する
63 let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
64 let sectionData = tableData[(indexPath as NSIndexPath).section]
65 // テーブルにWebListのデータを表示する
66 print("Table")
67 let webData = sectionData[(indexPath as NSIndexPath).row]
68 cell.textLabel?.text = webData.name
69 cell.detailTextLabel?.text = webData.url
70
71 return cell
72 }
73
74 // MARK: - Navigation
75
76 // セグエで移動する前にデータを受け渡す
77 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
78 // セグエがshowWebPageのときの処理
79 if segue.identifier == "showWebPage" {
80 //
81
82
83
84
85 print("ああああああああああああああああああああああああ(path)")
86
87 me.heru_Point(curPoint : Point, diffPoint : 1, path : path)
88
89
90 // me.Add_point()
91 // タップした行番号を取り出す
92 if let indexPath = self.tableView.indexPathForSelectedRow {
93 let sectionData = tableData[indexPath.section]
94 // 行のデータを取り出す
95 let webData = sectionData[(indexPath as NSIndexPath).row]
96 // 移動先のビューコントローラのdataプロパティに値を設定する
97 (segue.destination as! answerViewController).data = webData as! (name: String, url: String)
98 }
99 }
100 }
101
102
103
104 let fromAppDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
105
106 override func viewDidLoad() {
107 super.viewDidLoad()
108 self.me.getPath(name: self.fromAppDelegate.ThisUsername!, password: self.fromAppDelegate.Thispassword!, complete:{result in
109 print("きたこれ(result)しぱい")
110
111 self.path = result
112 })
113
114 let _ = self.me.getPoint(name: self.fromAppDelegate.ThisUsername, password: self.fromAppDelegate.Thispassword, complete:{result in
115 print("みずきち(result)")
116 self.Point = result
117
118 })
119
120 print("ここです!!!!!")
121 print(fromAppDelegate.ThisUsername)
122 print(fromAppDelegate.Thispassword)
123
124 let Questionnare = QuestionnareData()
125
126 //test1.makeQ(a: "男性",b: "心理系",c: "19",d: "google.com")
127 //test1.makeQ(a: "女性",b: "心理系",c: "19",d: "google.com")
128
129
130
131 /*let gender_age = me.getPrivacy(
132 name: self.fromAppDelegate.ThisUsername,
133 password: self.fromAppDelegate.Thispassword, complete:{result in
134 var arg_gender : String =
135 var arg_age : String =
136 })*/
137
138
139 //仮置きのプロフィール
140 var arg_gender = "男性"
141 var arg_age = "10代"
142
143 self.me.get_age_gender(name: self.fromAppDelegate.ThisUsername, password: self.fromAppDelegate.Thispassword, complete:{(age, gender) in
144 arg_gender = gender
145 arg_age = age
146 print("年齢, 性別")
147 print(arg_age)
148 print(arg_gender)
149 print("覚醒!!!!")
150
151 })
152
153 /*
154 func get_age_gender(name: String, password: String, complete: @escaping(String, String) -> ()){
155 */
156
157
158
159 Questionnare.getAllReports(gender: arg_gender, age: arg_age, completion: {
160 questions in
161 if(Questionnare.questions[safe: 3] != nil){
162 print("1OutofRange大丈夫!")
163 }else{
164 print("1OutofRange大丈夫じゃない")
165 }
166
167 /*func Section(completion: (Questionnare.questions) -> Void)
168
169 let ret = Section(Q: Questionnare.questions, completion: {*/
170
171
172 for Qs in Questionnare.questions {
173 if(Qs.category == "情報系"){
174 section0.append((name: Qs.theme, url: Qs.url))
175 }
176 else if(Qs.category == "心理系"){
177 print("いい感じ!!!")
178 print("(Qs.category), (Qs.theme), (Qs.url)")
179 section1.append((name: Qs.theme, url: Qs.url))
180 print(section1)
181 }
182 else if(Qs.category == "食物系"){
183 section2.append((name: Qs.theme, url: Qs.url))
184 }
185 else {
186 print("elseだよ〜")
187 }
188 }
189
190 tableData = [section0,section1,section2]
191
192 self.tableView.reloadData()
193
194 print(self.tableView as Any)
195
196 // テーブルのセルを参照する
197 //append test (できる)
198 //section1.append((name: "test", url: "test.com"))
199
200
201 //配列中身print
202 print("2回目 (Questionnare.questions)")})
203
204 //print("1回目 (result)")
205
206 /*if(result[safe: 3] != nil){
207 print("2OutofRange大丈夫!")
208 }else{
209 print("2OutofRange大丈夫じゃない")
210 }*/
211 }
212}
213
214//OutofRangeをチェックできるやつ
215extension Array {
216 subscript (safe index: Index) -> Element? {
217 //indexが配列内なら要素を返し、配列外ならnilを返す(三項演算子)
218 return indices.contains(index) ? self[index] : nil
219 }
220}
221
222
223