Я работаю над викториной. Я получаю вопросы от API. Я использую tableview для параметров.Как автоматически выбрать ячейку UITableview?
Теперь, когда пользователь выбирает ответ для 1-го вопроса & прессов Далее идет предыдущий вопрос. Затем выбранный ответ должен оставаться выбранным.
Я исследовал много и нашел это:
Programmatically emulate the selection in UITableViewController in Swift
Но я не могу автоматически выбрать пользователя выбранного ответа на мой взгляд таблицы.
Это мой Present UI
VC
func getOptions(){
OptionArray.removeAll(keepCapacity: false)
Alamofire.request(.GET, "http://www.wins.com/index.php/capp/get_chapter_answers/\(EID)/\(QuestionID[Qindex])")
.responseJSON { (_, _, data, _) in
println(data)
let json = JSON(data!)
let catCount = json.count
for index in 0...catCount-1 {
let disp = json[index]["DISPLAY_STATUS"].string
if disp == "Y"{
let op = json[index]["ANSWER"].string
self.OptionArray.append(op!)
let ans = json[index]["RIGHT_ANSWER"].string
self.AnswerArray.append(ans!)
}
}
self.OptionTable.reloadData()
println(self.OptionArray.count)
}
}
@IBAction func Previous(sender: AnyObject) {
Qindex--
ShowQuestion()
}
@IBAction func Next(sender: AnyObject) {
Qindex++
ShowQuestion()
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.OptionArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.OptionTable.dequeueReusableCellWithIdentifier("Option") as! OptionCell
cell.Optionlabel?.text = self.OptionArray[indexPath.row]
cell.layer.masksToBounds = true;
cell.layer.cornerRadius = 6;
cell.layer.borderWidth = 2.0
cell.layer.borderColor = colorsArray[1].CGColor
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indexPath = tableView.indexPathForSelectedRow();
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! OptionCell;
if currentCell.selected == true{
currentCell.layer.borderWidth = 4.0
currentCell.layer.borderColor = colorsArray[6].CGColor
println(currentCell.Optionlabel?.text)
}
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
let currentCell = tableView.cellForRowAtIndexPath(indexPath) as! OptionCell;
if currentCell.selected == false{
currentCell.layer.borderWidth = 2.0
currentCell.layer.borderColor = colorsArray[1].CGColor
}
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 70
}
UPDATE
У меня есть более 20 вопросов. Поэтому я должен сохранить выбранный ответ для каждого вопроса отдельно.
Я не могу выбрать ответ, используя позицию указателя, потому что параметры будут меняться в случайном порядке, когда он будет доступен во второй раз.
Он не выбирает вариант и смотрите обновление также пример проекта – user5184878
загрузки, если это возможно – iRiziya
К сожалению, это большой проект ... – user5184878