IOS:强制tableView单元格在点击时设置更改动画

IOS:强制tableView单元格在点击时设置更改动画,ios,uitableview,animation,Ios,Uitableview,Animation,我试图在点击附件视图时在单元格上执行动画。点击的委托方法正在启动,我可以让行做一些事情——更改标签,但它忽略了动画(或者在另一种情况下,甚至没有进行更改)。如何让动画正常工作 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ MyCustomCell *cell = [self.tableView cellForRow

我试图在点击附件视图时在单元格上执行动画。点击的委托方法正在启动,我可以让行做一些事情——更改标签,但它忽略了动画(或者在另一种情况下,甚至没有进行更改)。如何让动画正常工作

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{

    MyCustomCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

                    [UIView animateWithDuration:5.0
                                    delay: 5.0
                                    options: UIViewAnimationOptionCurveEaseIn
                                                                 animations:^{
//NEXT TWO LINES HAVE NO EFFECT ON CELL SO COMMENTED OUT
//cell.nameLabel.text = @"Thank you. FIRST ANIMATE TRY";                              
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
//NEXT THREE LINES CHANGE TEXT BUT WITHOUT ANIMATION
[self.tableView beginUpdates];
cell.nameLabel.text = @"Thank you. Second try!";
[self.tableView endUpdates];                                                                                
                             }
                             completion:^(BOOL finished){
                                 NSLog(@"animation finished");
                             }];     
    }

顺便说一句,我也尝试在主队列中显式地调度这个,但没有效果。它应该已经在主队列中。

首先,您不需要调用
beginUpdates
endUpdates
。其次,不能设置标签文本值更改的动画

您需要在单元格上有一个标签,并将
alpha
属性初始化为0.0。调用
accessoryButtonTappedForRowWithIndexPath
时,在动画块内将alpha属性设置为1.0

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AwesomeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.thankYouLabel.text = @"Thank you";
    cell.thankYouLabel.alpha = 0.0;
    return cell;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    AwesomeCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [UIView animateWithDuration:1.0 animations:^{
        cell.thankYouLabel.alpha = 1.0;
    }];
}

在[UIView AnimateWithDuration]方法中添加[self.view layoutifneed]方法你是说一个单元格有两个标签,一个是常规标签,然后是感谢标签?或者你是说有两个细胞,一个是普通细胞,另一个是单独的有感谢标签的超级细胞。