调度 sizeToFit 到后台
Dispatch sizeToFit to background
如何将此代码中的内容分派到后台线程
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self adjustTextToScreen];
}
-(void)adjustTextToScreen
{
//label
[self.detailedCommonLabel sizeToFit];
//tableV
CGRect frame = self.detailedCommonTableV.frame;
frame.size.height = self.detailedCommonTableV.contentSize.height;
self.detailedCommonTableV.frame = frame;
self.tableViewHeight.constant = self.detailedCommonTableV.frame.size.height;
//back scroll height
[self.detailedCommonScrollV setContentSize:CGSizeMake(self.detailedCommonScrollV.contentSize.width, self.detailedCommonImageSlider.frame.size.height + self.detailedCommonLabel.frame.size.height + self.detailedCommonTableV.frame.size.height + 40)];
}
是吧,因为计算时间太长了?
我尝试了不同的组合,但没有奏效。 sizeToFit
抛出一个异常,它必须在主线程中。 Realm 也会抛出一些异常。
您可以在主线程上执行一些 UI 操作时分派到主线程。
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
dispatch_async(dispatch_get_main_queue(), ^{
[self adjustTextToScreen];
});
}
-(void)adjustTextToScreen
{
//label
[self.detailedCommonLabel sizeToFit];
//tableV
CGRect frame = self.detailedCommonTableV.frame;
frame.size.height = self.detailedCommonTableV.contentSize.height;
self.detailedCommonTableV.frame = frame;
self.tableViewHeight.constant = self.detailedCommonTableV.frame.size.height;
//back scroll height
[self.detailedCommonScrollV setContentSize:CGSizeMake(self.detailedCommonScrollV.contentSize.width, self.detailedCommonImageSlider.frame.size.height + self.detailedCommonLabel.frame.size.height + self.detailedCommonTableV.frame.size.height + 40)];
}
如何将此代码中的内容分派到后台线程
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
[self adjustTextToScreen];
}
-(void)adjustTextToScreen
{
//label
[self.detailedCommonLabel sizeToFit];
//tableV
CGRect frame = self.detailedCommonTableV.frame;
frame.size.height = self.detailedCommonTableV.contentSize.height;
self.detailedCommonTableV.frame = frame;
self.tableViewHeight.constant = self.detailedCommonTableV.frame.size.height;
//back scroll height
[self.detailedCommonScrollV setContentSize:CGSizeMake(self.detailedCommonScrollV.contentSize.width, self.detailedCommonImageSlider.frame.size.height + self.detailedCommonLabel.frame.size.height + self.detailedCommonTableV.frame.size.height + 40)];
}
是吧,因为计算时间太长了?
我尝试了不同的组合,但没有奏效。 sizeToFit
抛出一个异常,它必须在主线程中。 Realm 也会抛出一些异常。
您可以在主线程上执行一些 UI 操作时分派到主线程。
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
dispatch_async(dispatch_get_main_queue(), ^{
[self adjustTextToScreen];
});
}
-(void)adjustTextToScreen
{
//label
[self.detailedCommonLabel sizeToFit];
//tableV
CGRect frame = self.detailedCommonTableV.frame;
frame.size.height = self.detailedCommonTableV.contentSize.height;
self.detailedCommonTableV.frame = frame;
self.tableViewHeight.constant = self.detailedCommonTableV.frame.size.height;
//back scroll height
[self.detailedCommonScrollV setContentSize:CGSizeMake(self.detailedCommonScrollV.contentSize.width, self.detailedCommonImageSlider.frame.size.height + self.detailedCommonLabel.frame.size.height + self.detailedCommonTableV.frame.size.height + 40)];
}