Iphone UITableViewRowAnimationBottom不';我不在最后一排工作

Iphone UITableViewRowAnimationBottom不';我不在最后一排工作,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我在这里遇到了一个非常类似的问题:,尽管没有给出答案。他的代码和我的代码也有点不同 我有一个非常简单的示例,它是从导航应用程序模板构建的 NSMutableArray *items; - (void)viewDidLoad { [super viewDidLoad]; items = [[NSMutableArray array] retain]; self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem a

我在这里遇到了一个非常类似的问题:,尽管没有给出答案。他的代码和我的代码也有点不同

我有一个非常简单的示例,它是从导航应用程序模板构建的

NSMutableArray *items;

- (void)viewDidLoad {
    [super viewDidLoad];
    items = [[NSMutableArray array] retain];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addItem)] autorelease];
}

- (void)addItem{
    [items insertObject:@"new" atIndex:0];
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationBottom];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return items.count;
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [items objectAtIndex:indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [items removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
    }   
}

问题是,当我插入或删除表中最后一行时,动画根本不起作用;该行立即出现或消失。这仅在UITableViewRowAnimationBottom中发生,但这正是以这种方式创建或删除表格单元格最有意义的动画。这是苹果框架中的一个bug吗?还是故意这样做?在计数中添加一个额外的单元格,然后设置该单元格,使其看起来根本不存在,只是为了避免这种行为,这样做有意义吗?

也许,使用UITableViewRowAnimationBottom,新单元格会“按原样”添加,而不带动画,其下的所有行都会通过滑动设置动画。因此,如果下面没有任何行,就不会有动画。

我使用类似的方法来设置行(dis)外观的动画,效果很好

if (oldRowCount < rowCount)
{
    // insert
    NSMutableArray* indexPaths = [NSMutableArray array];
    while (oldRowCount < rowCount)
    {
        [indexPaths addObject: [NSIndexPath indexPathForRow: oldRowCount inSection: section]];
        oldRowCount = oldRowCount + 1;
    }
    [self.tableView insertRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationTop];
}
else if (oldRowCount > rowCount)
{
    // remove
    NSMutableArray* indexPaths = [NSMutableArray array];
    while (rowCount < oldRowCount)
    {
        [indexPaths addObject: [NSIndexPath indexPathForRow: rowCount inSection: section]];
        rowCount = rowCount + 1;
    }
    [self.tableView deleteRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationTop];
}
if(oldRowCountrowCount)
{
//除去
NSMutableArray*索引路径=[NSMutableArray];
while(行计数<旧行计数)
{
[indexPaths addObject:[NSIndexPath indexPathForRow:rowCount片段:节]];
rowCount=rowCount+1;
}
[self.tableView deleteRowsAtIndexPaths:InExpaths with RowAnimation:UITableViewRowAnimationTop];
}

如果是最后一个单元格,我会尝试UITableViewRowAnimationTop或UITableViewRowAnimationFade。UITableViewRowAnimationBottom将单元格滑动到底部,不是吗?+1。如果您确实需要最后一行的动画,只需使用类似于
UITableViewRowAnimationFade
。这不是我想要的。。。我正在尝试使用UITableViewRowAnimationBottom,因为这是以这种方式添加或删除行的正确方法。出于这个目的,使用Top看起来有点奇怪,加上我已有的代码可以很好地使用Top,除了动画的外观。