0

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

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

4

1 回答 1

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

这样的东西。

于 2011-06-17T06:31:25.567 回答