0

i have two issues that are quite the same 1) I have a UIButton in a cell that calls a IBAction :

    - (IBAction)deleteFriend:(id)sender
{


CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self->table];

NSIndexPath *indexPath = [self->table indexPathForRowAtPoint:buttonPosition];
if (indexPath != nil)
   {
    UITableViewCell *cell = [self->table cellForRowAtIndexPath:indexPath];

    [UIView animateWithDuration:0.3 animations:^{

        cell.alpha = 0;
    } completion: ^(BOOL finished) {
        cell.hidden = YES;
        button.hidden = YES;


    }];
}

So basically i would like a confirm alert before the IBAction, but here is the problem. I don't know how to pass the sender to the buttonIndex of the UIAlertView so it can make the job of this IBAction

2) Here in the code i tell the cell ( the cell in the IBAction ) to hide, but also the button that i defined in cellforRowatIndexPath :

button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(272.0f, 15.0f, 30.0f, 30.0f);
[cell button];
[button addTarget:self action:@selector(deleteFriend:)
              forControlEvents:UIControlEventTouchUpInside];

but somehow it randomly hides other button in other cells. Why the heck doesn't it just hide in one cell ?

thanks in advance !

4

1 回答 1

0

下面是要做的事情:创建 UITableViewCell 的子类,然后创建单元格的 nib 文件,在 tableviews 类中,您必须将其添加到 viewDidLoad 方法

UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil]; 
[[self tableView] registerNib:nib forCellReuseIdentifier:@"CustomCell"]; 

创建标签、图片、按钮等,将操作方法​​放入单元格类中,并让它做任何你想让它做的事情

在您的 tableviews 类中,这是要使用的代码

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


TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
if (cell == nil) {
    cell = [[TableViewCell alloc] init]; // or your custom initialization
}


cell.name.text=[myName];
return cell;
}
于 2013-06-13T19:58:45.743 回答