MBProgressHUD showWhilePerformingSelector:在另一个线程上执行选定的方法?

时间:2011-06-17 02:45:43

标签: iphone multithreading mbprogresshud

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

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

1 个答案:

答案 0 :(得分:1)

您使用的是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 ,并在代表被解雇时将其删除。您应该运行连接,而不是改进格式化。只要您使用异步连接,一切都会正常。

类似于this