Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在视图上重新显示视图?_Ios_Objective C_Uiscrollview - Fatal编程技术网

Ios 如何在视图上重新显示视图?

Ios 如何在视图上重新显示视图?,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,我在视图中将出现以下代码: CGFloat typeViewHeight = self.scrollview.frame.size.height; CGFloat typeViewWidth = 120; for (UIView *view in [self.scrollview subviews]) { if([view isKindOfClass:[TypeSelectionItemView class]]) { [view removeFromSuperview]

我在
视图中将出现以下代码:

CGFloat typeViewHeight = self.scrollview.frame.size.height;
CGFloat typeViewWidth = 120;

for (UIView *view in [self.scrollview subviews]) {
    if([view isKindOfClass:[TypeSelectionItemView class]]) {
        [view removeFromSuperview];
    }
}

for (int i = 0; i < typeArray.count; ++i) {
    TypeSelectionItemView *typeView = nil;
    CGRect frame = CGRectMake(typeViewWidth * i, 0, typeViewWidth, typeViewHeight);
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TypeSelectionItemView" owner:self options:nil];
    for(id currentObject in topLevelObjects){
        if([currentObject isKindOfClass:[TypeSelectionItemView class]]){
            typeView = (TypeSelectionItemView *) currentObject;
            break;
        }
    }

    [self.typeScrollView setContentSize:CGSizeMake(typeViewWidth * (i + 1), typeViewHeight)];
    [self.typeScrollView addSubview:typeView];
}

视图中的代码移动到
视图将布局子视图

如果您需要在
viewdide出现之前获取任何视图的真实帧/大小

把这两行放在上面:

// Force scrollView to layout subview
scrollView.setNeedsLayout()
scrollView.layoutIfNeeded()
// ...

希望它有用

将代码放在
-(void)viewWillLayoutSubviews
方法中,而不是
viewwillbeen
中,然后它将被多次调用。仅在
viewWillLayoutSubviews内调用一次help@Rendy将代码移动到
视图willlayoutsubviews
,并使用布尔值检查并使其仅调用一次。请尝试@trungduc的建议。应该可以了是的,已经可以了。。早些时候,还有另一个问题,因此设法解决了这两个问题。。谢谢
// Force scrollView to layout subview
scrollView.setNeedsLayout()
scrollView.layoutIfNeeded()
// ...