Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView动态单元格内的YTPlayerView_Ios_Objective C_Youtube Api_Uicollectionview - Fatal编程技术网

Ios UICollectionView动态单元格内的YTPlayerView

Ios UICollectionView动态单元格内的YTPlayerView,ios,objective-c,youtube-api,uicollectionview,Ios,Objective C,Youtube Api,Uicollectionview,更新1: 以下是cellForItemAtIndexPath - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MBDynamicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifie

更新1:
以下是
cellForItemAtIndexPath

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

}];
原始问题

我在
UICollectionView
动态单元格中添加了
YTPlayerView

我的应用程序因“创建新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

更新问题时,我意识到自己做错了什么。
问题是我正在从后台线程重新加载collectionView。
因此,以下线路修复了碰撞

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

希望这对其他人有帮助。

你能发布一些代码吗?这对我来说不起作用。应用程序在iPhone 6、6s和所有模拟器上崩溃。