MBProgressHUD 是否显示WhilePerformingSelector:在另一个线程上执行选定的方法?

发布于 2024-11-16 03:18:24 字数 360 浏览 0 评论 0原文

我在我的项目中使用 MBProgressHUD。我使用的方法 showWhilePerformingSelector: 正在调用一个利用 NSURLConnection 的方法。我在另一个 Stack Overflow 问题中读到,人们在辅助线程中使用 NSURLConnection 时遇到问题,因为该线程会在委托方法被触发之前被终止。

本质上,问题是,MBProgressHUDshowWhilePerformingSelector: 方法是否在不同的线程上运行所选方法?如果是这样,我将如何利用该主线程来运行我的 NSURLConnection ?

I'm utilizing MBProgressHUD in my project. I'm using the method showWhilePerformingSelector: which is calling a method which utilizes NSURLConnection. I read in another Stack Overflow question that people were having trouble using NSURLConnection in a secondary thread because the thread would be killed before the delegate methods could be fired.

In essence, the question is, does MBProgressHUD's showWhilePerformingSelector: method run the selected method on a different thread? If so, how would I go about utilizing that main thread to run my NSURLConnection?

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

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

发布评论

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

评论(1

如果没有 2024-11-23 03:18:24

您使用的是哪个版本的 MBProgressHUD?在v0.4(最后一个),没有这样的方法。相反,是 showWhileExecuting,它表示:

    /**
 * Shows the HUD while a background task is executing in a new thread, then hides the HUD.
 *
 * This method also takes care of NSAutoreleasePools so your method does not have to be concerned with setting up a
 * pool.
 *
 * @param method The method to be executed while the HUD is shown. This method will be executed in a new thread.
 * @param target The object that the target method belongs to.
 * @param object An optional object to be passed to the method.
 * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
 * animations while disappearing.
 */
- (void)showWhileExecuting:(SEL)method 
                  onTarget:(id)target 
                withObject:(id)object 
                  animated:(BOOL)animated;

您应该做的是仅显示 HUD 并在委托被解雇时将其删除。您应该运行连接,而不是改进格式。只要您使用异步连接,一切都会好起来的。

这个之类的东西。

Which version of MBProgressHUD are you using? At v0.4 (the last on), there is no such method. Instead is showWhileExecuting, which says:

    /**
 * Shows the HUD while a background task is executing in a new thread, then hides the HUD.
 *
 * This method also takes care of NSAutoreleasePools so your method does not have to be concerned with setting up a
 * pool.
 *
 * @param method The method to be executed while the HUD is shown. This method will be executed in a new thread.
 * @param target The object that the target method belongs to.
 * @param object An optional object to be passed to the method.
 * @param animated If set to YES the HUD will disappear using the current animationType. If set to NO the HUD will not use
 * animations while disappearing.
 */
- (void)showWhileExecuting:(SEL)method 
                  onTarget:(id)target 
                withObject:(id)object 
                  animated:(BOOL)animated;

What you should do is show just the HUD and remove it when delegates are fired. You should run the connection, not the Improves formatting.. Everything will be OK as long as you use asynchronous connections.

Something like this.

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