2011-01-07 39 views
0

嗨:)
我正在開發一個iPhone應用程序,該應用程序應該從Web加載XML頁面並使用它進行操作。問題是應用程序在下載頁面時會凍結,而且看起來很醜。
我想展示某種「加載,請」帶旋轉輪的信息...
什麼是正確的方法?
我試圖用一個NSThread,但我收到此錯誤:

Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.

這是我使用加載XML頁面的OBJ-C代碼:
「正在加載」彈出菜單/進度條

NSString* xmlUrl = [NSString stringWithFormat:@"http://urltothexmlpage"]; 
NSString* XML = [NSString stringWithContentsOfURL:[NSURL URLWithString:xmlUrl] 
             encoding:NSUTF8StringEncoding 
              error:nil]; 

回答

2

我不知道你的應用程序的具體情況,但最好的情況是執行xml的異步請求。讓用戶等待並不是件好事。您可以使用ASIHTTPRequest來處理請求,因爲它是一個非常易於使用的框架。檢查「Creating an asynchronous request」部分。