2016-08-16 3 views
0

Update 1:
вот код для cellForItemAtIndexPathYTPlayerView внутри UICollectionView Dynamic Cell

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
    MBDynamicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath: 
            indexPath]; 
    video= videoData[indexPath.row]; 

    if(!cell) { 
     cell = [MBDynamicCollectionViewCell new]; 
    } 

    [cell.videoPlayer loadWithVideoId:video.videoID]; 

    cell.label1.text = [NSString stringWithFormat:@"%@",video.videoTitle]; 

    return cell; 
} 

и вот как я отправил запрос на сервер

NSURL *url=[ NSURL URLWithString:@"https://www.googleapis.com/youtube/v3/search?key=AIzaSyClU73k2yYl7gufFDxHU7uhGSCuM78f7Aw&channelId=UCW9CKYMhpJM-B1B0PGBB9Ew&part=snippet,id&order=date&maxResults=20"]; 

NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
NSOperationQueue *queue= [[NSOperationQueue alloc] init]; 
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){ 
    if(error){ 
     NSLog(@"error:%@", error.localizedDescription); 
    } 
    else{ 



     NSError *error; 
     NSMutableDictionary *allVideos= [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error]; 
     // NSString *string=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
     // NSLog(@"%@",string); 
     for(NSDictionary *dictionary in allVideos[@"items"]){ 

      NSDictionary *videoID=dictionary[@"id"]; 
      // NSLog(@"video id is %@", videoID[@"videoId"]); 
      NSDictionary *snippet= dictionary[@"snippet"]; 
      //NSLog(@"video title is %@", snippet[@"title"]); 
      NSDictionary *thumbnails= dictionary[@"snippet"][@"thumbnails"][@"default"]; 
      //NSLog(@"video image url is %@",thumbnails[@"url"]); 

      video=[[MBVideoClass alloc] initWithID:videoID[@"videoId"] withTitle:snippet[@"title"] withImg:thumbnails[@"url"] delegate:self]; 

      [videoData addObject:video]; 
     } 
     videoData= [NSMutableArray arrayWithArray:[videoData filteredArrayUsingPredicate:pred]]; 
     [self.collectionView reloadData]; 
    } 

}]; 

Orignal Вопрос

У меня есть dded YTPlayerView внутри UICollectionView Динамическая ячейка.
Мое приложение с ошибкой «плохой доступ при создании нового веб-представления»
Эта проблема возникает, когда я пытаюсь инициализировать webView внутри collectionView:cellForItemAtIndexPath:.
Любая идея?

1 0x7133239 StartWebThread() 
2 0x37579b7 __pthread_once_handler 
3 0x37695eb _os_once 
4 0x3757966 pthread_once 
5 0x7132fce WebThreadEnable 
6 0x610181a +[WebView(WebPrivate) enableWebThread] 
7 0x60fbcb0 WebKitInitialize 
8 0x85b8f0 ___UIApplicationLoadWebKit_block_invoke 
9 0x34109cd _dispatch_client_callout 
10 0x33fa26d dispatch_once_f 
11 0x33fa1cb dispatch_once 
12 0x85b7f8 _UIApplicationLoadWebKit 
13 0x21d9f59 _class_initialize 
14 0x21df981 lookUpImpOrForward 
15 0x21df8e1 _class_lookupMethodAndLoadCache3 
16 0x21ea547 objc_msgSend 
17 0x33161 -[MBVideoListCollectionViewController collectionView:cellForItemAtIndexPath:] 
18 0x11e45ee -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:] 
19 0x11e42ff -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] 
20 0x11e8761 -[UICollectionView _updateVisibleCellsNow:] 
21 0x11ed7df -[UICollectionView layoutSubviews] 
22 0x92b3d4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] 
23 0x21ed059 -[NSObject performSelector:withObject:] 
24 0x5c5b096 -[CALayer layoutSublayers] 
25 0x5c4e8b6 CA::Layer::layout_if_needed(CA::Transaction*) 
26 0x5c4e71a CA::Layer::layout_and_display_if_needed(CA::Transaction*) 
27 0x5c40ee7 CA::Context::commit_transaction(CA::Transaction*) 
28 0x5c75847 CA::Transaction::commit() 
29 0x5c75bef CA::Transaction::release_thread(void*) 
30 0x375929d _pthread_tsd_cleanup 
31 0x3758e22 _pthread_exit 
+1

можете ли вы разместить код? –

ответ

1

При обновлении вопроса я понял, что делаю неправильно.
Проблема в том, что я перезагружал collectionView из фонового потока.
Поэтому следующая строка фиксированной аварии

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self.collectionView reloadData]; 
}); 

Надежда это помогает кто-то другой.

Смежные вопросы