gpt4 book ai didi

ios - PureLayout 不是线程安全的

转载 作者:行者123 更新时间:2023-11-28 21:28:55 25 4
gpt4 key购买 nike

我将 UITableViewCell 子类化并使用 PureLayout 来应用约束,但应用程序终止并出现错误“PureLayout 不是线程安全的,必须从主线程中独占使用”。

在函数中...

 initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 

我刚刚应用了一个约束

[self.label autoSetDimension:ALDimensionHeight toSize:50];

删除后,应用程序不会崩溃

更新---可能是因为我正在异步调用 API

最佳答案

将您的 init 调用包装在 dispatch_async 到主线程中,然后...

没有看到您的其余代码。

dispatch_async(dispatch_get_main_queue(), ^{

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Something"];

});

但如果您需要这样做,我怀疑您的处理方式有误。您应该做的是使用异步调用的结果更新数据,并在 tableview 上调用 reloadData

有点像...

[SomeAPI loadSomeRemoteDataPleaseWithCompetion:^(NSArray *theNewData){

self.dataArray = theNewData;
//oh hai im a bad API and dont return in main thread
dispatch_async(dispatch_get_main_queue(), ^{

[self.tableview reloadData];

});

}];

关于ios - PureLayout 不是线程安全的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37013677/

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