Вы можете запускать SQL-запросы, включая объединение на MongoDB с mongo_fdw из Postgres.
Представление стека, безусловно, является способом ограничения любого количества представлений в столбце (или строке). Так что это звучит как лучший путь.
Это хитрый способ сделать это, но если вы знаете максимальное количество кнопок , которое у вас будет, вы можете добавить его непосредственно в свою ячейку собственного прототипа на раскадровке, не добавляя кнопки программно.
Решение (написано в Swift 4, но общий ответ)
CustomCellTableViewCell.swift
). Он будет содержать все ваши розетки компонентов пользовательского интерфейса. CustomCellTableViewCell.swift
. Теперь файл должен выглядеть примерно так: class CustomCellTableViewCell: UITableViewCell {
@IBOutlet weak var question: UILabel!
@IBOutlet weak var answerOne: UIButton!
@IBOutlet weak var answerTwo: UIButton!
...
...
@IBOutlet weak var answerEight: UIButton!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
. Не забудьте привести TableviewCell как CustomCell: let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell") as! CustomCellTableViewCell
var answerButtons = [cell.answerButtonOne, cell.answerButtonTwo..., cell.answerButtonEight]
for i in 0..<answerButtons.count {
if i < data[indexPath.row].answers.count { // if the answer exists, add it to the button
cell.answerButton[i].isHidden = false // show button if answer exists
cell.answerButton[i].setTitle(data[indexPath.row], for: .normal)
} else {
cell.answerButton[i].isHidden = true // hide that button
}
}