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

标签 iphone objective-c ios uitableview uiactivityindicatorview

我有一个名为 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 包含要上传的图像时,几秒钟后,带有图像的帖子出现在 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 会无限期地旋转(或至少延迟几秒钟),即使日志消息另有指示。这只在图片上传时中断,这一事实让我相信也许我应该在后台线程上发送请求,但我以前从未处理过线程,因此无法确定这是否是问题所在。

最后一件事,如果我导航到不同的 View 并返回,UIActivityIndi​​catorView 会显示为卡住状态 - 如果我导航离开并再次返回,它就会永远消失。

最佳答案

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

尝试在主线程中执行接口(interface)更改。使用 performSelectorOnMainThread:withObject:

关于iphone - UITableViewCell 中的 UIActivityIndi​​catorView 不会停止旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8455384/

相关文章:

javascript - 如何使用变量而不是常量

objective-c - UIScrollView 每次滚动时调用 layoutSubviews()

ios - 如何告诉 viewcontroller 从另一个类更新它的 UI

ios - 如何实现类似Apple News App或Pinterest ios的放大效果

iphone - 在 iOS 5 中启用隐藏的格鲁吉亚键盘

iphone - 您的 iPhone 应用程序测试策略是什么?

iphone - 延长 iOS 应用程序暂停时间

iphone - iOS 核心图形 : Stroking with semi-transparent patterns leads to colors corruption

ios - 内存泄漏: steady increase in memory usage with simple device motion logging

iPhone 随机数附加 URL