Uitableview 带有UI按钮的TableviewCell

Uitableview 带有UI按钮的TableviewCell,uitableview,ios4,Uitableview,Ios4,嗨。。 我有一个Tableview,每个单元格都有一个按钮,我现在以编程方式添加该按钮,我希望在按下该按钮时删除该单元格 任何人都可以帮我 这是一个样本,希望适用于您: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return rowCount; } // Row display. Implementers should *always* tr

嗨。。 我有一个Tableview,每个单元格都有一个按钮,我现在以编程方式添加该按钮,我希望在按下该按钮时删除该单元格


任何人都可以帮我

这是一个样本,希望适用于您:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return rowCount;

}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

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

    static NSString *cellIdentity = @"removable";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentity];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 70) reuseIdentifier:cellIdentity];
        UIButton *removeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 40)];
        [removeBtn setTitle:@"remove" forState:UIControlStateNormal];
        [removeBtn setBackgroundColor:[UIColor blueColor]];
        [removeBtn addTarget:self action:@selector(removeCell:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:removeBtn];
        [removeBtn release];

    }

    return cell;

}

- (void)removeCell:(id)button {

    UITableViewCell *cell = (UITableViewCell *)[(UIButton *)button superview];
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    NSArray *removeRow = [NSArray arrayWithObject:indexPath];

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:removeRow withRowAnimation:UITableViewRowAnimationFade];
    rowCount--;

    [self.tableView endUpdates];


}