Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何使用动画从tableview插入行_Iphone_Uitableview_Animation - Fatal编程技术网

Iphone 如何使用动画从tableview插入行

Iphone 如何使用动画从tableview插入行,iphone,uitableview,animation,Iphone,Uitableview,Animation,我是iphone新手,请帮助我,在我的应用程序中,通过web服务从sql server访问tableview时显示数据,但我的问题是,当插入新行并添加到tableview时,新输入的行被添加到tableview,但它添加正常,我想在将新行添加到tableview时添加动画。我不知道如何在输入新记录后将动画添加到tableview,任何人都有任何想法请告诉我。您可以使用方法-(void)insertRowsAtIndexPaths:(NSArray*)InExpaths with RowAnima

我是iphone新手,请帮助我,在我的应用程序中,通过web服务从sql server访问tableview时显示数据,但我的问题是,当插入新行并添加到tableview时,新输入的行被添加到tableview,但它添加正常,我想在将新行添加到tableview时添加动画。我不知道如何在输入新记录后将动画添加到tableview,任何人都有任何想法请告诉我。

您可以使用方法
-(void)insertRowsAtIndexPaths:(NSArray*)InExpaths with RowAnimation:(UITableViewRowAnimation)UITableView的动画

您可以使用方法
-(void)insertRowsAtIndexPaths:(NSArray*)使用行动画进行显示:(UITableViewRowAnimation)UITableView的动画

InsertRowsAndExpaths:WithRowsAnimation:

在接收器中的指定位置插入行 由一组 索引路径,带有设置动画的选项 插入

InsertRowsAndExpaths:WithRowsAnimation:

在接收器中的指定位置插入行 由一组 索引路径,带有设置动画的选项 插入

要插入行,请执行以下操作:

    int rowIndex = 0;//your row index where you want to add cell
    int sectionIndex = 0;//your section index
    NSIndexPath *iPath = [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];
    NSArray *array = [NSArray arrayWithObject:iPath];
    [self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
但您需要确保在
数据源
数组(用于填充表中数据的数组)的指定索引处有一条额外的记录。

要插入行:

    int rowIndex = 0;//your row index where you want to add cell
    int sectionIndex = 0;//your section index
    NSIndexPath *iPath = [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];
    NSArray *array = [NSArray arrayWithObject:iPath];
    [self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];

但是,您需要确保在
数据源
数组(用于填充表中数据的数组)的指定索引处有一条额外的记录。

问题:因此,如果您在tableview顶部插入数据,那么用户必须向下滚动以找到他离开的位置

解决方案:为什么不在tableview更新完成之前通过计算偏移量并设置偏移量来为用户向下滚动呢

如何计算该偏移量? (插入顶部的单元格数量)*(单元格高度)

注意:在下面的示例/计算中,我从插入的单元格数中减去两个单元格,以便用户可以预览顶部有数据

    [strongSelf.tableView beginUpdates];

    //INSERT DATA & CELLS ON TOP

    //REMOVE DATA ON BOTTOM IF NECESSARY

    //moving scrollview right back down so user can resume where last left off
    NSInteger estimatedRow = strongSelf.tableView.rowHeight * ( (indexPathsAdding.count) - 2);
    [strongSelf.tableView setContentOffset:CGPointMake(0, estimatedRow)];


    [strongSelf.tableView endUpdates];

问题:因此,如果在tableview顶部插入数据,那么用户必须向下滚动才能找到他离开的位置

解决方案:为什么不在tableview更新完成之前通过计算偏移量并设置偏移量来为用户向下滚动呢

如何计算该偏移量? (插入顶部的单元格数量)*(单元格高度)

注意:在下面的示例/计算中,我从插入的单元格数中减去两个单元格,以便用户可以预览顶部有数据

    [strongSelf.tableView beginUpdates];

    //INSERT DATA & CELLS ON TOP

    //REMOVE DATA ON BOTTOM IF NECESSARY

    //moving scrollview right back down so user can resume where last left off
    NSInteger estimatedRow = strongSelf.tableView.rowHeight * ( (indexPathsAdding.count) - 2);
    [strongSelf.tableView setContentOffset:CGPointMake(0, estimatedRow)];


    [strongSelf.tableView endUpdates];

谢谢你,但是我不知道如何使用这个方法。你能不能请你提供一个示例代码。