0

我正在尝试使用 UITableView 快速创建一个简单的匹配游戏,您必须将船类型与该船类型的定义相匹配。基本上,现在一切都被游戏搞砸了。单元格的样式设置为plain。以下是可能导致问题的方法的代码:

var currentSelectedText = "None"
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
    switch cell.textLabel.text! as String {
    case "Used to carry the pharoah":
        currentSelectedText = "Used to carry the pharoah"
    case "Used to carry bodies as a ceremony":
        currentSelectedText = "Used to carry bodies as a ceremony"
    case "Had a flat deck to carry a farmer's treasure":
        currentSelectedText = "Had a flat deck to carry a farmer's treasure"
    case "Daily, it made a trip around the world to carry Ra":
        currentSelectedText = "Daily, it made a trip around the world to carry Ra"
    case "Towed by smaller boats, carrying heavy objects":
        currentSelectedText = "Towed by smaller boats, carrying heavy objects"
    case "Used for business and pleasure by officials/nobles":
        currentSelectedText = "Used for business and pleasure by officials/nobles"
    case "Carried most Egyptians and some goods":
        currentSelectedText = "Carried most Egyptians and some goods"
    default:
        currentSelectedText = "None"
    }
    switch indexPath.row {
    case 7:
        switch cell.textLabel.text! as String {
        case "Ferry":
            if currentSelectedText == "Carried most Egyptians and some goods" {
                cell.textLabel.text = "Correct"
                cell.textLabel.textColor = UIColor.greenColor()
            } else if currentSelectedText == "None" {
            } else {
                performSegueWithIdentifier("Game End", sender: self)
            }
        case "Funeral Barge":
            if currentSelectedText == "Used to carry bodies as a ceremony" {
                cell.textLabel.text = "Correct"
                cell.textLabel.textColor = UIColor.greenColor()
            } else if currentSelectedText == "None" {
            } else {
                performSegueWithIdentifier("Game End", sender: self)
            }
        case "Cargo Boat":
            if currentSelectedText == "Towed by smaller boats, carrying heavy objects" {
                cell.textLabel.text = "Correct"
                cell.textLabel.textColor = UIColor.greenColor()
            } else if currentSelectedText == "None" {
            } else {
                performSegueWithIdentifier("Game End", sender: self)
            }

该行还有更多案例,一直到第 13 行(case 8, case 9, case 10 . . .)。我也有更多的船型(我有 7 种船型)。我还有一种方法可以取消选择行:

override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
    currentSelectedText = "None"
}

请记住,单元格样式设置为plain。问题是:

  1. 当我选择它时,单元格的文本变为“标题”。
  2. 我无法取消选择行
  3. 如果还有什么不适合与 UITableView 匹配的游戏,如果您列出我可以做些什么来解决这个问题,我将不胜感激。

如果我需要提供更多代码,请告诉我。谢谢!

4

0 回答 0