[問題] 有關dispatch_async的問題請教
在viewdidload裡面我加了兩條Thread
[NSThread detachNewThreadSelector:@selector(gotortsp) toTarget:self
withObject:nil];
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getUserProfileSuccess:)
name:@"Notification_GetUserProfileSuccess" object:nil]; });
-(void)gotortsp
{
[self runrtsp];
}
- (void) getUserProfileSuccess: (NSNotification*) aNotification
{
NSLog(@"in");
[self.spinner stopAnimating];
self.DisplaytoImage = [aNotification object];
}
由於runrtsp是建立一個live555連線一直傳封包進來讓ffmpeg解碼 解完碼再藉由
notification回傳到這裏的imageview update ui
我把回傳的寫在dispatch_get_main_queue();
為什麼沒辦法更新ui呢@@
可是log卻有印in的訊息 代表他有進來 但是卻沒有更新ui
由於runrtsp是個一直持續不間斷的收封包 所以只能做callback回來更新ui
因為不間斷 所以無法使用dispatch_queue_create()會一直卡在裡面...
應該要怎麼做才能夠確實的更新ui呢...拜託各位幫我解答了
--
作者 xoara (PURE) 看板 HatePolitics
標題 [新聞] 姚立明:柯P將以超過80萬票贏得北市長
時間 Sun Nov 9 19:39:20 2014
推
11/09 19:48,
11/09 19:48
推
11/09 19:50,
11/09 19:50
推
11/09 19:56,
11/09 19:56
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.167.9
※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1441856627.A.E12.html
※ 編輯: qnismine (1.34.167.9), 09/10/2015 11:44:19
推
09/10 13:44, , 1F
09/10 13:44, 1F
dispatch_get_main_queue();
我有這在這dispatch_async的block setimage 和 stop spinner 可是都沒動作..
※ 編輯: qnismine (1.34.167.9), 09/10/2015 14:08:51
→
09/10 14:19, , 2F
09/10 14:19, 2F
→
09/10 14:19, , 3F
09/10 14:19, 3F
→
09/10 14:21, , 4F
09/10 14:21, 4F
→
09/10 14:21, , 5F
09/10 14:21, 5F
→
09/10 14:24, , 6F
09/10 14:24, 6F
原來頻繁呼叫會有這個問題...我post資料是在別的類別下...解碼圖片後再post資料廣播
我在這裡寫的只有接收端而已...我之前是用nstimer來接 因為nstimer好像是獨立main
thread的...一直把image set到 imageview裡..只是久了偶爾會出現Bad Access,或delay
想說用別的方式來寫寫看 以前寫android的時候 是在一個message handler只要callback
回來就setimage到 imageview上 所以就用類似的nsnotificationcenter 做做看
不知道block怎麼寫一個callback 從別的類別能夠一直回傳資料到view controller上..
※ 編輯: qnismine (1.34.167.9), 09/10/2015 14:30:49
→
09/10 14:25, , 7F
09/10 14:25, 7F
→
09/10 14:35, , 8F
09/10 14:35, 8F
→
09/10 14:36, , 9F
09/10 14:36, 9F
推
09/10 17:25, , 10F
09/10 17:25, 10F
→
09/11 00:28, , 11F
09/11 00:28, 11F
→
09/11 00:29, , 12F
09/11 00:29, 12F
→
09/11 00:30, , 13F
09/11 00:30, 13F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章