Uitableview allowsMultipleSelection在Swift中不起作用?

Uitableview allowsMultipleSelection在Swift中不起作用?,uitableview,swift,ios8,multipleselection,Uitableview,Swift,Ios8,Multipleselection,我非常沮丧,因为它浪费了我很多时间。 我不知道为什么allowsMultipleSelection在我的TableView中不起作用? 为了让它工作,我做了所有的事情,但仍然没有结果。 请看一下我的代码,并请让我知道这个问题 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. self.p

我非常沮丧,因为它浪费了我很多时间。 我不知道为什么allowsMultipleSelection在我的TableView中不起作用? 为了让它工作,我做了所有的事情,但仍然没有结果。 请看一下我的代码,并请让我知道这个问题

override func viewDidLoad()
    {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        self.participantsTableView.allowsMultipleSelection = true
}

if tableView == participantsTableView
        {
            var cell = tableView.cellForRowAtIndexPath(indexPath)!

            if cell.accessoryType == UITableViewCellAccessoryType.Checkmark
            {
                cell.accessoryType = UITableViewCellAccessoryType.None
            }

            else
            {
                cell.accessoryType == UITableViewCellAccessoryType.Checkmark
            }

            self.participantsTableView.reloadData()
        }

您需要实现委托方法
tableView:did取消rowatinexpath:
,并在
tableView:cellforrowatinexpath:
中更新单元格的访问类型

像这样:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if let cell = tableView.cellForRowAtIndexPath(indexPath) {
        cell.accessoryType = .Checkmark
    }
}

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
    if let cell = tableView.cellForRowAtIndexPath(indexPath) {
        cell.accessoryType = .None
    }
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cellId", forIndexPath: indexPath) as UITableViewCell
    cell.textLabel?.text = String(indexPath.row)

    if let selectedPaths = tableView.indexPathsForSelectedRows() as? [NSIndexPath] {
        let selected = selectedPaths.filter(){ $0 == indexPath }
        if selected.count > 0 {
            cell.accessoryType = .Checkmark
        } else {
            cell.accessoryType = .None
        }
    }
    return cell
}

如果tableView==participantsTableView~,您将代码放在哪里?在函数
表视图中:didselectrowatinexpath:
?如果是这样,您不需要重新加载表。在“DidSelectRowatineXpath”中是的,我也尝试过同样的方法,但没有重新加载tableView!请在表的数据源方法
tableView:cellforrowatinexpath:
.var cell=UITableViewCell()cell=tableView.dequeueReusableCellWithIdentifier(“participantsCell”)中将代码发布为UITableViewCell.textlab.text=“test”返回单元格