2011-06-17 20 views
0

我在我的項目中使用了MBProgressHUD。我使用的方法是showWhilePerformingSelector:,它調用了一個使用NSURLConnection的方法。我在另一個Stack Overflow問題中讀到,人們在輔助線程中使用NSURLConnection時遇到問題,因爲在委託方法被觸發之前線程將被終止。MBProgressHUD showWhilePerformingSelector:在另一個線程上執行選定的方法嗎?

從本質上講,問題是,MBProgressHUDshowWhilePerformingSelector:方法在不同的線程上運行選定的方法嗎?如果是這樣,我將如何去利用該主線程來運行我的NSURLConnection

回答

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

+1

此外,最新的MBProgressHUD演示應用程序還包含一個NSURLConnection示例:https://github.com/matej/MBProgressHUD/blob/master/Demo/Classes/HudDemoViewController.m#L208 – 2011-06-17 13:30:13

相關問題