Iphone UITable查看单元格按钮问题

Iphone UITable查看单元格按钮问题,iphone,ios,uitableview,Iphone,Ios,Uitableview,我有一个自定义的表视图单元格,其中有两个UIButton和一个名为edit and cancel的文本字段,还有一个textField。当我在启用TextFeild交互的同时单击edit时,取消按钮图像应该更改。这对我来说很好 但当我点击编辑按钮时,另一个单元格取消bitton图像id自动更改!我知道这是因为我在重复使用手机!!但我找不到解决办法 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPa

我有一个自定义的表视图单元格,其中有两个UIButton和一个名为edit and cancel的文本字段,还有一个textField。当我在启用TextFeild交互的同时单击edit时,取消按钮图像应该更改。这对我来说很好

但当我点击编辑按钮时,另一个单元格取消bitton图像id自动更改!我知道这是因为我在重复使用手机!!但我找不到解决办法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    simpleTableIdentifier = @"MenuNameCell";
    cell = (MenuNameCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (!cell) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuNameCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        NSLog(@"---------new cell agin");          
    }
    else
    {
        for (UIView *view in [cell.contentView subviews])
                [view removeFromSuperview];
        NSLog(@"---------older use");
       // _checkButton = (UIButton *)[cell.contentView viewWithTag:indexPath.row];
       // _cancelButton = (UIButton *)[cell.contentView viewWithTag:indexPath.row];
    }

    // Creating Label Menu Name
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 11, 82, 21)];
    _nameLabel.backgroundColor = [UIColor clearColor];
    _nameLabel.text =  [_hotel._orderedMenus objectAtIndex:indexPath.row];

    // Creating Label Menu Cost
    _amountMenu   = [[UILabel alloc] initWithFrame:CGRectMake(167, 13, 44, 21)];
    _amountMenu.backgroundColor = [UIColor clearColor];
    _amountMenu.text  = [[_hotel._menuPrices objectAtIndex:indexPath.row] stringValue];

    // Creating Text Field For Order Quantity
    _textFieldQuantity = [[UITextField alloc] initWithFrame:CGRectMake(125,14,42,21)];
    _textFieldQuantity.userInteractionEnabled = NO;
    _textFieldQuantity.text = [[_hotel._selectedQuantity objectAtIndex:indexPath.row] stringValue];

    // Creating Button For Check Order
    _checkButton  = [UIButton buttonWithType:UIButtonTypeCustom];
    [_checkButton setFrame:CGRectMake(232, 13, 25, 28)];
    [_checkButton setBackgroundImage:[UIImage imageNamed:@"edit.png"]forState:UIControlStateNormal];
    [_checkButton addTarget:self action:@selector(editQuantity:) forControlEvents:UIControlEventTouchUpInside];
    [_checkButton setTag:indexPath.row];

    // Creating Button For CANCEL Order
    _cancelButton  = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelButton setFrame:CGRectMake(265, 13, 25, 28)];
    [_cancelButton setBackgroundImage:[UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal];
    [_cancelButton addTarget:self  action:@selector(cancelOreder:) forControlEvents:UIControlEventTouchUpInside];
    [_cancelButton setTag:indexPath.row];

    // Adding All To Call Content View
    [cell.contentView addSubview:_nameLabel];
    [cell.contentView addSubview:_amountMenu];
    [cell.contentView addSubview:_textFieldQuantity];
    [cell.contentView addSubview:_checkButton];
    [cell.contentView addSubview:_cancelButton];

    return cell;
}

哥们,我不认为这是因为重用细胞无论如何,如果你认为然后帮我一个忙,只要保持你的所有代码在如果;但是,尽管您必须检查您的点击事件中是否有任何改变您id的内容

还有一件事,通常我们习惯使用标签来达到这个目的,但我们手中有一件苹果公司提供的东西,用来解决这种事情,那就是联想。在这里,您应该尝试:-

*objc\u setAssociatedObject*

通过它,您始终可以引用您的单元格或与之关联的任何内容。 只需谷歌一下,我只是在下面粘贴了一个代码,检查一下:(但你需要根据你的要求工作)

请注意,由于工作繁忙,我只粘贴了一个代码,因此您需要按照您的要求进行a/c操作


如果有任何问题,请与我联系。

使用以下代码直接创建新单元,而不重复使用旧单元

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
而不是

cell = (MenuNameCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

请发布您的editQuantity:Method如果不是每个单词都以大写字母开头,您的问题将更容易阅读。-(iAction)editQuantity:(UIButton*)发件人{u textFieldQuantity.userInteractionEnabled=YES;button=(UIButton*)发件人;row=button.tag;NSLog(@“检查按钮索引为%d”,第行);UIImage*ButtonImageName=[UIImage ImageName:@“edit_over.png”];[\u checkButton setBackgroundImage:ButtonImageforState:UIControlStateNormal];UIImage*buttonImageCancel=[UIImage ImageName:@“check.png”];[u cancelButton setBackgroundImage:ButtonImageCancelforState:UIControlStateNormal];\u cancelButton.tag=0;]@occulus bettert你回答这个帖子的方式我在我的社交中得到了我的手机位置,但是如何将这个位置设置到我手机中的另一个按钮bcoz我想更改这个按钮的图像坦白地说,我没有得到,但是如果你需要设置不同手机上的其他按钮的位置,那么你能做的是,首先,你提到的那个按钮取框架意味着获取CGRect并再次重新加载你的表,这次在cellAtRowAtIndexPath中,只需将这个框架设置为你的按钮…太简单了…:)另外,告诉我你是否在找其他东西…:)
cell = (MenuNameCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];