BVB の回答を拡張するために、番号 10 に関しては、テーブルビュー デリゲート メソッドの Swift 3 スニペットを次に示します。xib 内のすべてのセルに必ずアウトレットを追加してください。
テーブル ビュー セクションを手動で作成する場合、indexPath
はテーブル構造を表す 2 次元配列に等しいことに注意してください。たとえば、が にindexPath
渡されるtableView(cellForRowAt indexPath: IndexPath)
と[1][0]
、セルは 2 番目のセクションの最初の位置に配置されます。
indexPath
値は、プロパティindexPath.row
およびから引き出すことができますindexPath.section
。これらの値を使用して、任意の順序で IBOutlets からセクションを手動で構築できます。
@IBOutlet var is_enabled: UITableViewCell!
@IBOutlet var is_public: UITableViewCell!
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch(section){
case 0:
return "Cell 1"
case 1:
return "Cell 2"
default: return ""
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("index path here", indexPath)
if(indexPath.section == 0) {
return is_enabled
}
else if(indexPath.section == 1) {
return is_public
} else {
return is_enabled
}
}