繁体   English   中英

如何根据通过表视图的选择在uiview中显示不同的视图控制器(请参见说明中的图像)?

[英]How do I display different view controllers in a uiview depending on selection through a tableview (Please see the image in description)?

我想使用ObjectiveC创建一个具有产品列表视图的ios应用。 我正在为此列表创建一个筛选器屏幕,该筛选器屏幕具有一个表视图和另一个视图,该视图根据在第一个表视图中选择的行显示不同的自定义视图控制器。 我正在从流行的电子商务应用程序上传类似屏幕的屏幕截图。

在此处输入图片说明

您能帮我处理如何在uiview中显示不同的ViewController的部分吗? 提前致谢!

如果您很少有自定义视图控制器可以随机播放,请使用容器视图

为此,使用scrollView可以轻松实现您的要求:)

scrollView =[[UIScrollView alloc]init];
        scrollView.frame =CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height - 60);
        scrollView.pagingEnabled=YES;
        scrollView.delegate=self;
        scrollView.bounces=NO;
        scrollView.showsHorizontalScrollIndicator = YES;
        scrollView.showsVerticalScrollIndicator = NO;
        scrollView.scrollsToTop=NO;
        scrollView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
        [self.view addSubview:scrollView];
        scrollView.contentSize=CGSizeMake(2*scrollView.frame.size.width, scrollView.frame.size.height - 60);

        collectionantZ *homeScreen =[self.storyboard instantiateViewControllerWithIdentifier:@"yyy"];
        Antzclubtableview *antzClub =[self.storyboard instantiateViewControllerWithIdentifier:@"xxx"];

        tableView1.view.frame=CGRectMake(0,19,scrollView.frame.size.width, scrollView.frame.size.height);
        tableView2.view.frame=CGRectMake(scrollView.frame.size.width,19,scrollView.frame.size.width, scrollView.frame.size.height);

        [scrollView addSubview:tableView1.view];
        [scrollView addSubview:tableView2.view];


        [self addChildViewController:tableView1];
        [self addChildViewController:tableView2];

在按钮动作中执行以下操作:

- (IBAction)tableView1:(id)sender {
    [scrollView setContentOffset:CGPointMake(0,0.) animated:YES];
}
- (IBAction)tableView2:(id)sender {
    [scrollView setContentOffset:CGPointMake(1 *scrollView.frame.size.width,0.) animated:YES];
}

如果您有多个视图控制器,只需根据需要调整此代码

暂无
暂无

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

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