Ios 如何在重复使用单元格的情况下更改按钮上的图像

Ios 如何在重复使用单元格的情况下更改按钮上的图像,ios,uitableview,cell,Ios,Uitableview,Cell,有一个问题。我需要在一个按钮的触摸添加到阵列和在按钮改变图像。 我是这样做的: - (IBAction)addUserAction:(UIButton *)sender { CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *clickedButtonIndexPath = [self.tableView indexPathForRowAtPoint:touchP

有一个问题。我需要在一个按钮的触摸添加到阵列和在按钮改变图像。 我是这样做的:

- (IBAction)addUserAction:(UIButton *)sender {

CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView];

NSIndexPath *clickedButtonIndexPath = [self.tableView indexPathForRowAtPoint:touchPoint];

NSInteger row = clickedButtonIndexPath.row;

UserCell* selectedCell = [self.tableView cellForRowAtIndexPath:clickedButtonIndexPath];

NSString* login = selectedCell.loginLabel.text;

BOOL userIsExist = selectedCell.isExist;

for (QBUUser* user in self.users) {

    if ([login isEqualToString:user.login]) {

        if (!userIsExist) {

            [self.assistant.usersInCurrentChat addObject:user];

            userIsExist = YES;

            UIButton* button = self.buttons[clickedButtonIndexPath.row];

            [button setImage:[UIImage imageNamed:@"delete_icon_64x64.png"] forState:UIControlStateNormal];

            self.buttons[clickedButtonIndexPath.row] = button;

        } else{

            [self.assistant.usersInCurrentChat removeObject:user];

            userIsExist = NO;

            UIButton* button = self.buttons[clickedButtonIndexPath.row];

            [button setImage:[UIImage imageNamed:@"add_button_64x64.png"] forState:UIControlStateNormal];

            self.buttons[clickedButtonIndexPath.row] = button;


        }
    }
}

selectedCell.isExist = userIsExist;
}
我的cellForRowAtIndexPath代码:

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

UserCell* cell = [tableView dequeueReusableCellWithIdentifier:@"userCell1"];

if(!cell){

    cell = [[UserCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"userCell1"];

}

QBUUser* user = [self.users objectAtIndex:indexPath.row];

cell.loginLabel.text = [NSString stringWithFormat:@"%@", user.login];

NSInteger currentTimeInterval = [[NSDate date] timeIntervalSince1970];

NSInteger userLastRequestAtTimeInterval   = [[user lastRequestAt] timeIntervalSince1970];

// if user didn't do anything last 1 minute (60 seconds)
if((currentTimeInterval - userLastRequestAtTimeInterval) > 60){

    cell.statusImageView.image = [UIImage imageNamed:@"offline_icon_45x45.png"];

} else{

    cell.statusImageView.image = [UIImage imageNamed:@"online_icon_32x32.png"];

}

NSInteger row = indexPath.row;

if ([self.buttons[indexPath.row] isEqual:[NSNull null]]) {

    self.buttons[indexPath.row] = cell.button;

} else {

    cell.button = self.buttons[indexPath.row];

}

return cell;
}
但是细胞被“重用”,我得到的结果如图所示 我该如何解决这个问题