Ios UIButton未选择正确的单元格

Ios UIButton未选择正确的单元格,ios,uitableview,uibutton,Ios,Uitableview,Uibutton,在我的tableview中,自定义单元格中有一个按钮 我使用代表对按钮进行操作 按钮图像仅在选定单元格上更改 我的问题是: 当我按下按钮时: 所选单元格工作正常,按钮更改正确(正确) 选定单元格后的第二个单元格不会更改按钮(已更正) 第三个单元格重复所选单元格的操作(错误) 这是无休止的重复,我不明白为什么 该按钮应仅更改选定单元格,而不更改其他非选定单元格 你能帮我吗 -(void)ButtonPressedGoPoint:(FFCustomCellWithImage *)custom b

在我的tableview中,自定义单元格中有一个按钮

我使用代表对按钮进行操作

按钮图像仅在选定单元格上更改

我的问题是:

当我按下按钮时:

  • 所选单元格工作正常,按钮更改正确(正确)
  • 选定单元格后的第二个单元格不会更改按钮(已更正)
  • 第三个单元格重复所选单元格的操作(错误)
这是无休止的重复,我不明白为什么 该按钮应仅更改选定单元格,而不更改其他非选定单元格

你能帮我吗

-(void)ButtonPressedGoPoint:(FFCustomCellWithImage *)custom button:(UIButton *)gopointpressed {


    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"it_IT"]];
    NSNumber *likeCount = [numberFormatter numberFromString:custom.CountGoPoint.text];

    if (!custom.AddGoPoint.selected) {
        NSLog(@"TastoSelezionato");
        likeCount = [NSNumber numberWithInt:[likeCount intValue] + 1];
        custom.CountGoPoint.text = [NSString stringWithFormat:@"%@", likeCount];

       [custom.AddGoPoint setBackgroundImage:[UIImage imageNamed:@"FFIMG_Medal_Blu"] forState:UIControlStateNormal];
    }

    else  {
        if ([likeCount intValue] > 0) {
            likeCount = [NSNumber numberWithInt:[likeCount intValue] - 1];
            custom.CountGoPoint.text = [NSString stringWithFormat:@"%@", likeCount];
        }

        NSLog(@"TastoDeselezionato");
       [custom.AddGoPoint setBackgroundImage:[UIImage imageNamed:@"FFIMG_MedalADD"] forState:UIControlStateNormal];

    }

    custom.AddGoPoint.selected = !custom.AddGoPoint.selected;


}
这是我对tableview的实现

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    self.PostDetails = [ArrayforPost objectAtIndex:indexPath.row];
    static NSString *IdentificazioneCellaIMG = @"CellaIMG";
        FFCustomCellWithImage * CellaIMG = (FFCustomCellWithImage * )[self.FFTableView dequeueReusableCellWithIdentifier:IdentificazioneCellaIMG];
        if (CellaIMG == nil) {
            CellaIMG = [[FFCustomCellWithImage alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:IdentificazioneCellaIMG ];
        }

        CellaIMG.delegate = self;

     CellaIMG.tag = indexPath.row;
       [CellaIMG.AddGoPoint setTag:indexPath.row];

        if ([self AssignedGoPointToPost:self.PostDetails]) {
            CellaIMG.AddGoPoint.selected =YES;
             [CellaIMG.AddGoPoint setImage:[UIImage imageNamed:@"FFIMG_Medal_Blu"] forState:UIControlStateNormal];
        } else {
            CellaIMG.AddGoPoint.selected =NO;
             [CellaIMG.AddGoPoint setImage:[UIImage imageNamed:@"FFIMG_MedalADD"] forState:UIControlStateNormal];
        }

        NSString *FotoPostSocial = [self.PostDetails objectForKey:FF_POST_IMMAGINE];
        CellaIMG.FotoPost.file = (PFFile *)FotoPostSocial;
        [CellaIMG.FotoPost loadInBackground];
        CellaIMG.FotoPost.layer.masksToBounds = YES;
        CellaIMG.FotoPost.layer.cornerRadius = 2.0f;
        CellaIMG.FotoPost.contentMode = UIViewContentModeScaleAspectFill;

        CellaIMG.backgroundCell.layer.masksToBounds = YES;
        CellaIMG.backgroundCell.layer.cornerRadius = 2.0f;
        CellaIMG.backgroundCell.layer.borderColor = [UIColor colorWithRed:(219/255.0) green:(219/255.0) blue:(219/255.0) alpha:(1)].CGColor;
        CellaIMG.backgroundCell.layer.borderWidth = 1.0f;
        CellaIMG.backgroundCell.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        CellaIMG.LeggiCommentoButton.layer.cornerRadius = 2.0f;
        CellaIMG.FotoProfilo.layer.masksToBounds = YES;
        CellaIMG.FotoProfilo.layer.cornerRadius = 25.0f;
        CellaIMG.FotoProfilo.contentMode = UIViewContentModeScaleAspectFill;

        CellaIMG.TestoPost.font = [UIFont fontWithName:@"Helvetica" size:14.0f];
        NSString *text = [self.PostDetails objectForKey:FF_POST_TEXT];
        CellaIMG.TestoPost.text = text;
        [CellaIMG.TestoPost setLineBreakMode:NSLineBreakByTruncatingTail];
        NSString *NomeUser = [[self.PostDetails objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_NOMECOGNOME];
        CellaIMG.NomeUtente.text = NomeUser;
        NSString *ImmagineUtente = [[self.PostDetails objectForKey:FF_POST_UTENTE] objectForKey:FF_USER_FOTOPROFILO];
        CellaIMG.FotoProfilo.file = (PFFile *)ImmagineUtente;
        [CellaIMG.FotoProfilo loadInBackground];

        if (CellaSelezionata == indexPath.row) {
            CGFloat AltezzaLabel = [self valoreAltezzaCella: indexPath.row];
            CellaIMG.TestoPost.frame = CGRectMake(CellaIMG.TestoPost.frame.origin.x, CellaIMG.TestoPost.frame.origin.y, CellaIMG.TestoPost.frame.size.width, AltezzaLabel);  }

        else {
            CellaIMG.TestoPost.frame = CGRectMake(CellaIMG.TestoPost.frame.origin.x, CellaIMG.TestoPost.frame.origin.y, CellaIMG.TestoPost.frame.size.width, 65);
        }

        return CellaIMG;

        }
    }

你能在tableview数据源中展示你的
cellForRowAtIndexPath:
实现吗谢谢回复Rich,我编辑了我的帖子