简体   繁体   English

一个UIViewController中有多个UIView

[英]Multiple UIView in one UIViewController

I am developing a iPad App. 我正在开发iPad App。 There is one UIViewController which should show all relevant information. 有一个UIViewController应该显示所有相关信息。 Inside this VC there are 2 UIViews: The first UIView on the first half of the Screen shows a Image and some text. 在此VC中,有2个UIView:屏幕上半部分的第一个UIView显示一个Image和一些文本。 The second View on the bottom half of the screen should display some stuff like a map or a image gallery depending on the button that was pressed in the center of the screen. 屏幕下半部分的第二个“视图”应显示一些内容,例如地图或图像库,具体取决于在屏幕中央按下的按钮。

My first try was to load for example a GalleyViewController and then get his View and add this as a Subview to my BottonView like this: 我的第一个尝试是加载例如GalleyViewController,然后获取他的View并将其作为子视图添加到我的BottonView中,如下所示:

-(void)galleryButtonPressedInCenter{
    GalleryViewController * gal = [[GalleryViewController alloc] initWithNibName:@"GalleryViewController" bundle:nil];
    [gal.view setFrame:CGRectMake(0,0,620,300)];
    [self.bottomView addSubview: gal.view];

But this will crash my app if I touch the View with my finger. 但是,如果我用手指触摸“视图”,这将使我的应用程序崩溃。

To show what I want to achieve: On the last Screenshot ( http://itunes.apple.com/de/app/ebookers-hotels-furs-ipad/id465464927?mt=8 ) you can see that in this App there is a ImageView and some other Stuff in the upper part and in the lower part there are multiple Views that are switched depending on the button that was pressed. 要显示我想要实现的目标:在上一个屏幕截图( http://itunes.apple.com/de/app/ebookers-hotels-furs-ipad/id465464927?mt=8 )中,您可以看到此应用程序中有一个ImageView和其他一些东西在上部和下部,有多个视图,这些视图根据所按下的按钮进行切换。

Make an empty fullscreen view. 制作一个空的全屏视图。 then add your subviews to that view. 然后将您的子视图添加到该视图。

  ViewController
      -UIView  (your new umbrella view)
          -UIView  (subView 1)
          -UIView (subview 2)

I don't think I've seen it documented in the helpfiles, but I'm finding that each "ViewController" can only have one UIView directly attached. 我认为我没有在帮助文件中看到它,但是我发现每个“ ViewController”只能直接附加一个UIView。 I'm kinda new at this though, try it anyway :) 我对此还是有点陌生​​,还是尝试一下:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM