Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Objective c 每次使用动画时,UITableView不会滚动到底部_Objective C_Ios_Uitableview_Animation - Fatal编程技术网

Objective c 每次使用动画时,UITableView不会滚动到底部

Objective c 每次使用动画时,UITableView不会滚动到底部,objective-c,ios,uitableview,animation,Objective C,Ios,Uitableview,Animation,我有一个UITableView,在程序执行期间动态添加新行。我总是在底部添加新行,当这种情况发生时,我希望表格视图滚动到底部并显示新行 NSInteger oldCount = [self.game count]; dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ //This may take a long time BOOL gameStateChanged = [sel

我有一个UITableView,在程序执行期间动态添加新行。我总是在底部添加新行,当这种情况发生时,我希望表格视图滚动到底部并显示新行

NSInteger oldCount = [self.game count];
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    //This may take a long time
    BOOL gameStateChanged = [self.game update] ;
    dispatch_async( dispatch_get_main_queue(), ^{
        if (gameStateChanged)
        {
            NSMutableArray* ipaths = [NSMutableArray arrayWithCapacity:5];
            NSInteger newCount = [self.game count];
            for (NSInteger i = oldCount; i < newCount; i++)
            {
                [ipaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
            }
            NSIndexPath* ipath = [ipaths lastObject];
            [self.wordsTableView insertRowsAtIndexPaths:ipaths 
                                       withRowAnimation:UITableViewRowAnimationNone];
            [self.wordsTableView scrollToRowAtIndexPath: ipath 
                                       atScrollPosition:UITableViewScrollPositionBottom 
                                               animated:YES];
        }
    });
});
问题是它有时会停止滚动。停止滚动后,除非用户手动滚动表视图,否则它不会在随后调用同一方法时自行开始滚动


如果我关闭滚动动画,发送动画:否,它工作得很好。这怎么可能?如何使用动画使其工作?

在调用该方法时尝试等待,直到完成…另一种可能是集成动画:动画块中没有函数

诸如此类:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];

[self.wordsTableView scrollToRowAtIndexPath: ipath 
                                       atScrollPosition:UITableViewScrollPositionBottom 
                                               animated:NO];

[UIView commitAnimations];

这并不是最好的解决方案,但可能会有所帮助……

等待是指不同时启动两个动画?我试着了解一下这种制作动画的方式,它说从iOS 4.0开始就不鼓励这样做。我真的不想创建自己的动画,因为它内置于UITableView中。