2016-08-16 63 views
0

更新1中:
这里是cellForItemAtIndexPathYTPlayerView一个UICollectionView动态小区

- (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]; 
    } 

}]; 

一部开拓创新的问题

我有一个dded YTPlayerView里面有一个UICollectionView动态单元格。
我的应用程序在创建新的Web视图时出现“访问错误”时发生错误
当我尝试在collectionView:cellForItemAtIndexPath:内部初始化webView时出现此问题。
有什么想法?

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]; 
}); 

希望这有助于任何人。

相关问题