1

我正在做什么创建 aUIImageView并希望将其添加到 aUIScrollingView作为其滚动内容,但它从未出现。所以我尝试了下面的代码,现在问题对我来说很清楚了。如何将子视图添加到另一个子视图?

 //in myViewController.m
 @synthesize scrollView = _scrollView;
 - (void) viewDidLoad{ 
     UIView* simpleView = [[UIView alloc] initWithFrame:CGRectMake(0,0,300,200)];
     [simpleView setBackgroundColor: [UIColor BlueColor]];
     [self.view addSubview: simpleView]  //this would work, the simple view appears
     [self.scrollView addSubview: simpleView]  //this would not work, the simple view doesn't appear
 }

scrollView 属性与情节提要中的 ScollView 挂钩,这是该控制器中唯一的东西

4

3 回答 3

1

你需要这样做:

[self.view addSubview: scrollview]  
[self.scrollView addSubview: simpleView] 

基本上在另一个之上添加一个并不是所有东西都堆叠在视图上。自我顶部视图顶部的图像几乎

于 2012-05-10T03:56:04.410 回答
0

一种可能性:滚动视图可能未链接到scrollViewxib/storyboard 中的属性。在这个方法中设置一个断点并检查它。

于 2012-05-10T03:55:02.600 回答
0

一个视图只能有一个超级视图。

所以当你这样做时:

[self.view addSubview: simpleView];
[self.scrollView addSubview: simpleView];

您只需将 simpleView superView 设置为 self.view,然后将其替换为 self.scrollView。simpleView 不再是 self.view 的子视图。

正如 ECEsurfer 所说,堆叠您的观点:

[self.view addSubview: scrollview];
[self.scrollView addSubview: simpleView];

希望能帮助到你 !

于 2012-05-10T10:50:35.010 回答