UITableViewCell 中的 UIActivityIndi​​catorView 不会停止旋转

发布于 2024-12-20 15:53:04 字数 1370 浏览 0 评论 0原文

我有一个名为 AccountView 的 UITableViewCell 子类,其中包含 UIActivityIndi​​catorView。每个单元格都应该包含一个 Twitter 帐户。当用户向 Twitter 发布消息时,UIActivityIndi​​catorView 应该开始旋转,然后在执行 twitter 请求处理程序时停止动画:

[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error){
        if (error != nil) {
            NSLog(@"TWITTER ERROR: %@",error);
        }
        NSLog(@"Posted successfully");
        AccountCell *cell = (AccountCell *)[accountTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[accounts indexOfObject:account] inSection:0]];
        NSLog(@"Cell isSpinning?  :%d",[[cell activity] isAnimating]);
        [[cell activity] stopAnimating];
        NSLog(@"Cell isSpinning?  :%d",[[cell activity] isAnimating]);
    }];

向 Twitter 发布短消息时,这一切都可以正常工作,但是,当 TWRequest 包含要显示的图像时,UIActivityIndi​​catorView 应该开始 旋转。上传后,几秒钟后,带有图像的帖子出现在 Twitter 上,我在控制台中看到以下消息:

2011-12-10 00:13:22.085 TwitTest[14954:1a03] Posted Successfully
2011-12-10 00:13:22.086 TwitTest[14954:1a03] Cell isSpinning?  :1
2011-12-10 00:13:22.088 TwitTest[14954:1a03] Cell isSpinning?  :0

但是 UIActivityIndi​​catorView 继续无限期地旋转(或至少延迟几秒钟),即使日志消息另有指示。事实上,这只与图像上传有关,这让我相信也许我应该在后台线程上发送请求,但我以前从未处理过线程,并且无法确定这是否是问题所在。

最后一件事,如果我导航到不同的视图并返回,UIActivityIndi​​catorView 会显示为冻结 - 如果我导航离开并第二次返回,那么它就会永远消失。

I have a subclassed UITableViewCell named AccountView which contains an UIActivityIndicatorView. Each cell is supposed to contain a Twitter account. When the user posts a message to Twitter, the UIActivityIndicatorView is supposed to start spinning, then stop animating when the twitter request handler is executed:

[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error){
        if (error != nil) {
            NSLog(@"TWITTER ERROR: %@",error);
        }
        NSLog(@"Posted successfully");
        AccountCell *cell = (AccountCell *)[accountTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[accounts indexOfObject:account] inSection:0]];
        NSLog(@"Cell isSpinning?  :%d",[[cell activity] isAnimating]);
        [[cell activity] stopAnimating];
        NSLog(@"Cell isSpinning?  :%d",[[cell activity] isAnimating]);
    }];

This all works fine when posting a short message to Twitter, however, when the TWRequest contains an image to be uploaded, after a few seconds, the post with image appears on Twitter, and I see the following message in the console:

2011-12-10 00:13:22.085 TwitTest[14954:1a03] Posted Successfully
2011-12-10 00:13:22.086 TwitTest[14954:1a03] Cell isSpinning?  :1
2011-12-10 00:13:22.088 TwitTest[14954:1a03] Cell isSpinning?  :0

But the UIActivityIndicatorView keeps spinning indefinitely (or at least a delay of several seconds), even though the Log messages indicate otherwise. The fact that this only breaks with image upload leads me to believe that maybe I should send the request on a background thread, but I have never dealt with threads before, and couldn't say for sure if that is the problem.

One last thing, if I navigate to different view and return, the UIActivityIndicatorView appears frozen - if I navigate away and return a second time, then it disappears for good.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月静好 2024-12-27 15:53:04

来自 Apple 开发人员文档:“不保证在任何特定线程上调用此处理程序。”也许您的接口循环正在工作,并且在每次运行循环后都会考虑修改。

尝试在主线程中执行界面更改。使用performSelectorOnMainThread:withObject:

From Apple Developer's documentation: "This handler is not guaranteed to be called on any particular thread." Perhaps your interface loop is working and modifications are taken in account after each run loop.

Try to execute interface changes in main thread. Use performSelectorOnMainThread:withObject:

时间海 2024-12-27 15:53:04

您可以尝试添加以下行:

[CATransaction flush];

在发送 stopAnimating 消息后。如果问题是事件循环速度不够快,这将有所帮助。从您提供的内容来看,尚不清楚这是问题所在,但值得一试。请参阅此问题与解答了解背景信息。

更新您需要在头文件中添加#import,并确保您已使用构建阶段添加了 QuartzCore 框架(目标中的“链接二进制文件与库”选项。

You could try adding the line:

[CATransaction flush];

after you've sent the stopAnimating message. This will help if the issue is that the event loop isn't coming around quickly enough. Not clear that this is the issue from what you provide, but worth a try. See this question and answer for background.

Updated you'll need to add #import <QuartzCore/QuartzCore.h> in the header file and make sure you've added the QuartzCore framework using the Build Phases (Link Binary With Libraries) option in Targets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文