gpt4 book ai didi

ios - 访问单例类时 View 卡住几秒钟

转载 作者:行者123 更新时间:2023-11-29 01:39:56 26 4
gpt4 key购买 nike

这是我正在使用的方法

 +(dataHandler *)getDataHandler
{

dispatch_once(&internalOnceToken,^{
internalInstance = [[dataHandler alloc] init];
if(internalInstance) {
NSLog(@"Internal instance created: %@", internalInstance);
}
});
if(internalOnceToken == -1)
{
NSLog(@"Internal instance exists: %@", internalInstance);
}
return internalInstance;

}

我尝试使用dispatch_asyn,但它不是静态分配,在我的主屏幕中,我可以访问所有数据并存储在我的单例类中。

但是当我尝试从一个 View Controller 转到主屏幕时,它会挂起几秒钟,如何克服这个问题?

调用单例方法:

 -(void)responseFunction:(NSMutableDictionary *)response
{
BOOL sucess;
sucess =[[response objectForKey:@"sucess"]boolValue];
NSLog(@"response Method%@",response);
NSString *subimages;

if(!sucess)
{
//storing response data to singleton class.
}
[self datahandlers];//here i am calling singleton.
}

存储后,我在 View 中调用单例类加载方法

if([file.dicCategoryDetails count]!=0&&[file.dicProductDetails count]!=0)
{
[self datahandlers];
}

这是数据处理方法

-(void)datahandlers
{
for(NSDictionary *diccategory in file.categoryArr)
{
NSMutableDictionary *dicparsing=[[NSMutableDictionary alloc]init];
[dicparsing setObject:[diccategory objectForKey:@"category"] forKey:@"category"];
[dicparsing setObject:[diccategory objectForKey:@"name"] forKey:@"name"];
[dicparsing setObject:[diccategory objectForKey:@"image"] forKey:@"image"];
[dicparsing setObject:[diccategory objectForKey:@"subcategory"] forKey:@"subcategory"];
[ArrName addObject:dicparsing];

}
NSLog(@"inside data handler%@",ArrName);
[collectionview reloadData];
[self scrollView];

}

View 中已加载

 file= [dataHandler getDataHandler];

最佳答案

最后我只使用dispatch_async(dispatch_get_main_queue(),^{})

 if([file.dicCategoryDetails count]!=0&&[file.dicProductDetails count]!=0)
{
dispatch_async(dispatch_get_main_queue(), ^{

[self datahandlers];
});

}

关于ios - 访问单例类时 View 卡住几秒钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32524425/

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