简体   繁体   中英

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

I want to create an ios app, using objectiveC, which has a products list view. I am looking to create a filter screen for this list, which has a tableview and another view which displays different custom viewcontrollers depending on the row selected in the first tableview. I am uploading a screenshot of a similar screen from a popular ecommerce app.

在此处输入图片说明

Can you please help me on how to handle the part where I will have to display different viewcontrollers in the uiview. Thanks in advance!

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

Use scrollView for this it is easy to achieve your requirements:)

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];

in button Action do this:

- (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];
}

if you have multiple view controller just adjust this code as per your need

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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