簡體   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