gpt4 book ai didi

iphone - 如何在 iOS 中释放 subview

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

这是添加 subview 的代码,我想在添加 subview 之前检查它。

numberOfViews = [[GlobalVariable sharedInstance].itemNewsDetail count];


for (int i = 0; i < numberOfViews; i++) {
@try{
CGFloat xOrigin = i * 320;
CGRect frame;
frame.size = CGSizeMake(320, 365);
frame.origin.x = xOrigin;
frame.origin.y = 0;

detailVC = [[DetailScrollVC alloc]initWithNibName:@"DetailScrollVC" bundle:nil];
detailVC.view.frame = frame;
[detailVC loadViewByIndex:i];

UIFont *font = detailVC.txtBodyNews.font;
detailVC.txtBodyNews.font = [font fontWithSize:currentFontSize];
detailVC.txtBodyNews.tag = i;

[scrollDetail addSubview:detailVC.view];
[scrollDetail sizeToFit];
[detailVC.view release];
}@catch (NSException *exception) {
NSLog(@"ERROR HANDLING : %@",exception);
}
}

如何检查和释放我之前已经添加的所有 subview 。

谢谢。

最佳答案

如果您想从 ScrollView 或任何其他 View 中删除 subview 而不是尝试此代码:

 numberOfViews = [[GlobalVariable sharedInstance].itemNewsDetail count];

for (UIView *subviewElement in scrollDetail.subviews)
{
[subviewElement removeFromSuperview];
}

for (int i = 0; i < numberOfViews; i++)
{
@try
{
CGFloat xOrigin = i * 320;
CGRect frame;
frame.size = CGSizeMake(320, 365);
frame.origin.x = xOrigin;
frame.origin.y = 0;

detailVC = [[DetailScrollVC alloc]initWithNibName:@"DetailScrollVC" bundle:nil];
detailVC.view.frame = frame;
[detailVC loadViewByIndex:i];

UIFont *font = detailVC.txtBodyNews.font;
detailVC.txtBodyNews.font = [font fontWithSize:currentFontSize];
detailVC.txtBodyNews.tag = i;

[scrollDetail addSubview:detailVC.view];
[scrollDetail sizeToFit];
[detailVC release];
}
@catch (NSException *exception) {
NSLog(@"ERROR HANDLING : %@",exception);
}
}

希望对您的理解有所帮助。谢谢

关于iphone - 如何在 iOS 中释放 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16475313/

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