我创建了两个名为第一部分和第二部分的数组,用于将数据输入到我的表中。
sectionTitles
我创建了一个名为let sectionTitles = ["Section1" , "Sectoin2"]
的数组,其中包含我的部分名称。
public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
return sectionTitles[section]
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
switch section {
case 0 :
return Sec1.count
default:
return Sec2.count
}
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = challengeTable.dequeueReusableCell(withIdentifier: cellID) as! CustomisedCell
cell.selectionStyle = .none
switch indexPath.section {
case 0:
cell.CAChallengeTitle.text = Sec1[indexPath.row]
cell.CAChallengeDescription.text = "\(Sec1[indexPath.row]) "
cell.CAChallengeButt.tag = indexPath[1]
cell.CAChallengeButt.setTitle("I am interested >", for: .normal)
print("Done with sectoin 0")
default:
cell.CAChallengeTitle.text = Sec2[indexPath.row]
cell.CAChallengeDescription.text = "\(Sec2[indexPath.row]) "
cell.CAChallengeButt.tag = indexPath[1]
cell.CAChallengeButt.setTitle("I am interested >", for: .normal)
print("Done with sectoin 1")
}
return cell
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
let height : CGFloat = 60
return height
}
然后我有以下委托表视图函数:
#!/bin/bash
# Athena queries are fundamentally Asynchronous. So we have to :
# 1) Make the query, and tell Athena where in s3 to put the results (tell it the same place as the UI uses).
# 2) Wait for the query to finish
# 3) Pull down the results and un-wacky-Jsonify them.
# run the query, use jq to capture the QueryExecutionId, and then capture that into bash variable
queryExecutionId=$(
aws athena start-query-execution \
--query-string "SELECT Count(*) AS numBooks FROM books" \
--query-execution-context "Database=demo_books" \
--result-configuration "OutputLocation"="s3://whatever_is_in_the_athena_UI_settings" \
--region us-east-1 | jq -r ".QueryExecutionId"
)
echo "queryExecutionId was ${queryExecutionId}"
# Wait for the query to finish running.
# This will wait for up to 60 seconds (30 * 2)
for i in $(seq 1 30); do
queryState=$(
aws athena get-query-execution --query-execution-id "${queryExecutionId}" --region us-east-1 | jq -r ".QueryExecution.Status.State"
);
if [[ "${queryState}" == "SUCCEEDED" ]]; then
break;
fi;
echo " Awaiting queryExecutionId ${queryExecutionId} - state was ${queryState}"
if [[ "${queryState}" == "FAILED" ]]; then
# exit with "bad" error code
exit 1;
fi;
sleep 2
done
# Get the results.
aws athena get-query-results \
--query-execution-id "${queryExecutionId}" \
--region us-east-1 > numberOfBooks_wacky.json
# Todo un-wacky the json with jq or something
# cat numberOfBooks_wacky.json | jq -r ".ResultSet.Rows[] | .Data[0].VarCharValue"
答案 0 :(得分:4)
您尚未实施numberOfSections
数据源方法。
func numberOfSections(in tableView: UITableView) -> Int {
return sectionTitles.count
}
如果没有这个,该表假定有1个部分。
答案 1 :(得分:0)
您必须实现tableView的numberOfRowsInSection方法
如果您只使用静态sactions,则必须返回numberOfRowsInSection方法中的节数。否则,将所有部分存储在一个数组中并返回
Array.count