gpt4 book ai didi

ios - UICollectionView 动态单元格内的 YTPlayerView

转载 作者:行者123 更新时间:2023-12-01 20:05:35 26 4
gpt4 key购买 nike

更新 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];
}

}];

原始问题

我已添加 YTPlayerViewUICollectionView 内动态单元格。
我的应用程序因“创建新 Web View 时访问不正确”而崩溃
当我尝试在 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];
});

希望这对其他人有帮助。

关于ios - UICollectionView 动态单元格内的 YTPlayerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38974973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com