[請益] 請問在發送電文與等待時做的處理?

作者: tga123 (叛帝)   2015-11-05 11:04:39
各位鄉民好
我最近碰到一個問題是說
在做網路相關的程序時
手機螢幕會暫時凍結直到伺服器端回應為止
於是我開了兩條執行緒
//播放讀取中的動畫
[NSThread detachNewThreadSelector:@selector(STLOAD)
toTarget:self withObject:nil];
//執行電文交換
[NSThread detachNewThreadSelector:@selector(net_conoet)
toTarget:self withObject:nil];
一開始這樣沒有問題
但是最近看IOS9似乎在新開執行緒做UI的更動會有問題
於是我將讀取動畫改為主執行緒
然後電文交換繼緒使用新開執行緒
最近需要使用伺服器傳回來的參數
做畫面的跳轉
[usere dismissViewControllerAnimated:YES completion:nil];
一樣不能透過主執行緒以外的執行緒控制畫面跳頁
想要請問鄉民們針對與伺服器溝通上
有沒有什麼比較好的處理方式呢?
作者: uranusjr (←這人是超級笨蛋)   2015-11-05 11:52:00
就... 在更新 UI 時回到 main thread 啊, 不然呢
作者: tga123 (叛帝)   2015-11-05 13:52:00
聽起來好像很難orz 我在研究看看 感謝鄉民提供意見
作者: cryinglove (毓™)   2015-11-05 21:17:00
在收到傳回參數時,寫個主執行緒的工作
作者: tentenlee (天天)   2015-11-06 01:24:00
用GCD的main thread不難吧?
作者: tga123 (叛帝)   2015-11-06 10:15:00
好的大概有個方向了,感謝鄉民,可能我觀念不夠清楚才會覺得難

Links booklink

Contact Us: admin [ a t ] ucptt.com