【问题标题】:Multiple Choice App Feature多项选择应用程序功能
【发布时间】:2015-02-05 01:06:07
【问题描述】:
我正在尝试为应用创建一个简单的多项选择测验功能。我有一个包含所有问题、多项选择和答案的 pList。这些问题有不同数量的多项选择题。大多数问题有 4 个选项,但其他问题有 5、6 或 7 个。我无法更改每个问题中的选项数量。我不知道是否应该使用 Interface Building 来构建 XIB 文件,或者我应该根据多项选择选项的数量以编程方式为每个 UILabel 和 UIButton 创建约束。此应用仅适用于 iPad 和 iOS 7 和 8。
【问题讨论】:
标签:
ios
ios8
interface-builder
nslayoutconstraint
【解决方案1】:
一种选择是将答案放在 UITableView 中,然后每个答案只是一个单元格,您可以在 Interface Builder 中完成所有操作。
第二个选项,如果你知道你永远不会有超过 8 个答案,那就是把所有 8 个 UILabel 都放进去,并将未使用的标签设置为隐藏。然后您可以在界面生成器中完成所有操作,只需在代码中切换隐藏属性即可。
【解决方案2】:
Use UITableView
Question fill in section
Answer options fill in rows of section
In number of section
{
return no of questions
}
In number of rows for section
{
return no of answer for that section(question)
}
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
{
Fill the questions
}
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
fill the answer
}