Iphone UitableView中的Uibutton

Iphone UitableView中的Uibutton,iphone,uitableview,uibutton,Iphone,Uitableview,Uibutton,我在uitableview的每一行中都添加了一个uibutton,现在,每当用户单击uitableview中的任何按钮时,我都想删除该按钮。请帮助我解决这个问题,我已经添加了带有indexPath.row的按钮标记,然后启动了一个包含可变数组的方法,然后我将[sender标记]添加到可变数组中,并重新加载tableview和单元格中的行,我正在检查数组是否包含对象,如果是,则将标签放置在按钮上。UIButton是UIView类的子类。它具有-removeFromSuperview方法。请注意,您

我在
uitableview
的每一行中都添加了一个
uibutton
,现在,每当用户单击
uitableview
中的任何按钮时,我都想删除该按钮。请帮助我解决这个问题,我已经添加了带有
indexPath.row
的按钮标记,然后启动了一个包含可变数组的方法,然后我将[sender标记]添加到可变数组中,并重新加载tableview和单元格中的行,我正在检查数组是否包含对象,如果是,则将标签放置在按钮上。

UIButton是UIView类的子类。它具有-removeFromSuperview方法。请注意,您必须检查该单元格是否已在-tableView:cellforrowatinexpath方法上移除了按钮。

我已经尝试过,希望这也适用于您

-(IBAction)buttonAction:(id)sender
    {
        UIButton *mybutton =(UIButton *)sender;
        [mybutton removeFromSuperview];
    }

- (UITableViewCell *) tableView:(PullDownTableView *)tableView cellInRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = @"cellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier] autorelease];
    }

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(230, 2, 60, 25);
    [myButton setBackgroundColor:[UIColor clearColor]];
    [myButton setTitle:@"Button" forState:UIControlStateNormal];
    [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:headerButton];
    return cell;
}

myButton.tag=indexPath.row是标识要删除的UIButton所必需的。因此,在UITableViewCell中为每个创建的UIButtons设置一个唯一的标记

下面是修改后的示例代码

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(230, 2, 60, 25);
myButton.tag = indexPath.row;
[myButton setBackgroundColor:[UIColor clearColor]];
[myButton setTitle:@"Button" forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:headerButton];

UIButton需要唯一标识符才能删除点击的UIButton。@iApple:谢谢您的回复,如果我们要删除任何具有特定描述的按钮,我认为唯一标识符是必要的。但在这种情况下,无论点击哪个按钮,都应该删除/删除。因此,在按钮操作中,发件人将被删除。如果我错了,请指导我谢谢所有有价值的建议,但我想要的是:-(iAction)按钮点击:(id)发件人{[向服务器提出自我请求,向此朋友提出]如果当时我得到了成功的响应,我想删除uibutton并在该行上放置一个标签,我开始了解removeFromSuperView方法,但我也想放置一个标签,这对我来说是一个开销,请给我一些建议。感谢所有有价值的建议,但我想要的是这样:-(iAction)Button单击:(id)sender{[self requesttotheserver to addthis friend]如果当时我得到了成功的响应,我想删除uibutton并在该行上放置一个标签,我开始了解removeFromSuperView方法,但我也想放置一个标签,这对我来说是一个开销,请给我一些建议。
add below code in cellForRowAtIndexPath method 
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(230, 2, 60, 25);
    myButton.tag = indexPath.row;
    [myButton setBackgroundColor:[UIColor clearColor]];
    [myButton setTitle:@"Click to remove" forState:UIControlStateNormal];
    [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:myButton];


//button action metod
-(void)buttonAction:(UIButton *)sender
{
    [sender removeFromSuperview];
}