看板 MacDev 關於我們 聯絡資訊
大家好 大概的架構是在UITableView上面貼了兩個CollectionView 我原本用下列這種方式,CollectionView是可以正確的改變大小 [UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{ CollectionView.frame = CGrectRectMake = (0,0,300,300); } completion:^(BOOL finished) { menu_status =1; } ]; 但自從我在ViewDidLoad加了dispatch_async後 上面的程式碼就無法跑出原本的效果,畫面中frame大小並未改變 但我用NSLog在動畫前跟後印出frame大小,數值是有改變的 請大大們指點要怎麼修改?謝謝 附上dispatch_async部分代碼 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // 抓取Json資料 NSArray * itemParser = [self jsonDataParserArray:WebUrl]; dispatch_async(dispatch_get_main_queue(), ^{ //將Json資料加到Array裡面以後reloadData顯示畫面 firstDictionary = [[NSMutableDictionary alloc]init]; FileName = [[photoArray objectAtIndex:photoIndex] objectForKey:@"iconFile"]; [firstDictionary setObject:FileName forKey:@"image"]; [Tableview reloadData]; }); }); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.71.209.227 ※ 文章網址: http://www.ptt.cc/bbs/MacDev/M.1418446552.A.FB7.html ※ 編輯: chengpocheng (42.71.209.227), 12/13/2014 13:00:24 ※ 編輯: chengpocheng (42.71.209.227), 12/13/2014 13:02:16
s8911124: dispatch_get_main_queue UI操作要在mainthread下 12/13 13:48
chengpocheng: 謝謝S大給我的靈感,問題解決了 12/13 15:58
chengpocheng: 由於在抓JSON資料時會先創造UICollectionView一次 12/13 16:03
chengpocheng: 在CellAtIndex加個陣列數不為0的判斷式就解決了3Q 12/13 16:10