iOS UITableViewCell取消选择问题

iOS UITableViewCell取消选择问题,ios,uitableview,Ios,Uitableview,我目前正在为一位当地兽医开发一款应用程序,这样他的客户就可以从他们的iPhone上订购产品。我遇到了一个奇怪的错误,即我不能在动态表中取消选择TableViewCells 当我在tableview中按下一个单元格时,它会像平常一样被选中。但是,当我第二次选择单元格时,它不会取消选择第一个单元格。即使按下已选定的单元格,也不会取消选择 有人知道我做错了什么或我应该做什么来解决这个问题吗 编辑: 以下是我选择表格的代码: - (void)tableView:(UITableView *)tableV

我目前正在为一位当地兽医开发一款应用程序,这样他的客户就可以从他们的iPhone上订购产品。我遇到了一个奇怪的错误,即我不能在动态表中取消选择TableViewCells

当我在tableview中按下一个单元格时,它会像平常一样被选中。但是,当我第二次选择单元格时,它不会取消选择第一个单元格。即使按下已选定的单元格,也不会取消选择

有人知道我做错了什么或我应该做什么来解决这个问题吗

编辑:

以下是我选择表格的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

hasCellSelected = YES;
cell1 = [tableView cellForRowAtIndexPath:indexPath];
cell2 = [tableView dequeueReusableCellWithIdentifier:@"medicineCell"
         forIndexPath:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
long row = [indexPath row];
cell2.medicineLabel.text = [_medicineArray objectAtIndex:row];
if (prevIndexPath && ![prevIndexPath isEqual:indexPath])
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
prevIndexPath = indexPath;



}

如果要取消选择当前选定的单元格,可以使用以下代码

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

如果要取消选择以前选择的单元格,只需将上述方法更新为

NSIndexPath * prevIndexPath;

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
    if (prevIndexPath && ![prevIndexPath isEqual:indexPath])
    {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    }

    prevIndexPath = indexPath;
}

“多重选择”属性设置为“是”

选择您的表,查看Xcode右侧的属性面板,其中有一个“allowMultipleSelection”属性。解开它

或者将其放在viewDidLoad方法中

self.tableView.allowsMultipleSelection=NO;

如果没有看到你迄今为止所做的尝试(即:一个最小的例子),你很难知道你错在哪里。因此,我建议用一些有问题的代码更新您的问题。我添加了您的代码,但表格单元格保持选中状态。问题是dequeueReusableCellWithIdentifier:@“medicineCell”行,但我不知道如何修复它。我们不想取消选择PrevindXPath处的行吗?